Re: return two elements - Mailing list pgsql-general

From Michael Fuhr
Subject Re: return two elements
Date
Msg-id 20050608141632.GA71686@winnie.fuhr.org
Whole thread Raw
In response to Re: return two elements  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: return two elements  (Alvaro Herrera <alvherre@surnet.cl>)
List pgsql-general
On Wed, Jun 08, 2005 at 01:28:56AM -0400, Tom Lane wrote:
> Alvaro Herrera <alvherre@surnet.cl> writes:
> > Hmm, be aware that you can't return a set if you have OUT/INOUT
> > parameters.
>
> ?  News to me --- what are you worried about exactly?
>
> It's surely possible that our idea of what this means is different
> from Oracle's, but we ought to take a close look before the semantics
> get set in stone by a release ...

I see the following in the development documentation -- are the
semantics still under discussion?  Should this thread be moved to
pgsql-hackers?

"If you declared the function with output parameters, write just
RETURN NEXT with no expression.  The current values of the output
parameter variable(s) will be saved for eventual return.  Note that
you must declare the function as returning SETOF record when there
are multiple output parameters, or SETOF sometype when there is
just one output parameter of type sometype, in order to create a
set-returning function with output parameters."

http://developer.postgresql.org/docs/postgres/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING

The following example works in HEAD:

CREATE FUNCTION foo(INOUT y integer, OUT z integer) RETURNS SETOF record AS $$
BEGIN
    y := y + 1; z := y + 2; RETURN NEXT;
    y := y + 1; z := z + 3; RETURN NEXT;
    y := y + 1; z := z + 4; RETURN NEXT;
END;
$$ LANGUAGE plpgsql;

SELECT * FROM foo(1);
 y | z
---+----
 2 |  4
 3 |  7
 4 | 11
(3 rows)

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: "Magnus Hagander"
Date:
Subject: Re: vulnerability/SSL
Next
From: Douglas McNaught
Date:
Subject: Re: Backup Compatibility between minor versions.