Re: record to columns: syntax question and strange behaviour

From: Thomas Pundt <mlists(at)rp-online(dot)de>
To: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: record to columns: syntax question and strange behaviour
Date: 2009-10-27 17:20:46
Message-ID: 4AE72BEE.5070801@rp-online.de
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

Marc Mamin schrieb:
> how should I retrieve the result from a function with some OUT
> paramenters?
>
> (PG is 8.3.7)
>
> here a short example to illustrate my question:
>
> CREATE OR REPLACE FUNCTION test (In a int, OUT b int, OUT c int) AS
> $BODY$
> BEGIN
> b:=a+1;
> c:=a+2;
> raise notice 'done: %', a;
> END
>
> $BODY$
> LANGUAGE 'plpgsql' IMMUTABLE

IMO easiest would be to include a RETURNS SETOF record in the
function declaration and a return next; statement in the function
body. E.g.

CREATE OR REPLACE FUNCTION test (In a int, OUT b int, OUT c int)
RETURNS SETOF record
AS
$BODY$
BEGIN
b:=a+1;
c:=a+2;
return next;
END
$BODY$
LANGUAGE 'plpgsql'

and then issue

SELECT * FROM test(1);

Ciao,
Thomas

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Marc Mamin 2009-10-27 18:46:50 Re: record to columns: syntax question and strange behaviour
Previous Message Marc Mamin 2009-10-27 16:08:07 record to columns: syntax question and strange behaviour