Re: Select in function?

From: andrew(at)modulus(dot)org
To: Alfonso Peniche <alfonso(at)iteso(dot)mx>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Select in function?
Date: 2001-02-07 00:49:09
Message-ID: Pine.BSF.4.21.0102071146380.30849-100000@jander.fl.net.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


As per the documentation at:
http://postgresql.planetmirror.com/users-lounge/docs/7.0/user/c40874113.htm#AEN4207

When using SELECT in a PL/PGSQL function, you must either SELECT .. INTO or
use the PERFORM query if you don't care about the return value from a
SELECT. If you wish to use the special FOUND variable, you have to SELECT
.. INTO.

Hope that helps,

Andrew.

On Tue, 6 Feb 2001, Alfonso Peniche wrote:

> I have the following function:
>
> CREATE FUNCTION RegistrarDesconexion( integer )
> RETURNS integer
> AS '
> BEGIN
> UPDATE BitacoraConexion
> SET Desconexion = CURRENT_TIMESTAMP
> WHERE IdBitacoraConexion = $1;
> SELECT Desconexion FROM BitacoraConexion
> WHERE IdBitacoraConexion = $1;
> IF FOUND THEN
> RETURN 1;
> ELSE
> RETURN 0;
> END IF;
> END;'
> LANGUAGE 'plpgsql';
>
> and if I run:
> select registrardesconexion (5);
>
> I get the following error:
> ERROR: unexpected SELECT query in exec_stmt_execsql()
>
> I don't know what's wrong, though I assume it's saying I'm not allowed
> to use the select statement where it is.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Warren Vanichuk 2001-02-07 01:04:02 Re: Deadlock issues (was: Re: [GENERAL] selecting a random record)
Previous Message Stephan Szabo 2001-02-07 00:42:33 Re: Select in function?