Re: return two elements

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)surnet(dot)cl>, Rodríguez Rodríguez, Pere <prr(at)hosppal(dot)es>, pgsql-general(at)postgresql(dot)org
Subject: Re: return two elements
Date: 2005-06-08 14:16:32
Message-ID: 20050608141632.GA71686@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 08, 2005 at 01:28:56AM -0400, Tom Lane wrote:
> Alvaro Herrera <alvherre(at)surnet(dot)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/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Együd Csaba 2005-06-08 14:31:33 FW: Where to find translation of Postgres error messages?
Previous Message Magnus Hagander 2005-06-08 14:08:31 Re: vulnerability/SSL