Re: Select in function?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
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:42:33
Message-ID: Pine.BSF.4.21.0102061637170.45220-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


It wants you to do a
SELECT INTO <var> ...
in the function, something like

'DECLARE
rec RECORD
BEGIN
...
SELECT INTO rec Desconexion FROM BitacoraConexion
...
'

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.
>
> Any ideas or comments.
>
> Thanx.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message andrew 2001-02-07 00:49:09 Re: Select in function?
Previous Message Tom Lane 2001-02-07 00:41:59 Re: selecting a random record