Thread: Question on returning Rows in a stored proc

Question on returning Rows in a stored proc

From
Richard Sickler
Date:
Hi,

I'm new to pl/pgsql and while exploring the world of writing stored procs, I came up with a question that I hope some kind person can help me with, namely, how does one return a bunch of rows?
From the examples that I've found on the web, I can return and integer, a real, etc.  But if I wanted to return the results of something like a query, (e.g. SELECT * FROM foo), how would I do that?

Rich

Re: Question on returning Rows in a stored proc

From
Andreas Kretschmer
Date:
Richard Sickler <richard.sickler@avagotech.com> wrote:

> Hi,
>
> I'm new to pl/pgsql and while exploring the world of writing stored procs, I
> came up with a question that I hope some kind person can help me with, namely,
> how does one return a bunch of rows?
> From the examples that I've found on the web, I can return and integer, a real,
> etc.  But if I wanted to return the results of something like a query, (e.g.
> SELECT * FROM foo), how would I do that?

Create your function as "... returns setof ... ", read more:
http://www.postgresql.org/docs/8.3/interactive/plpgsql-control-structures.html

and/or:

18:13 < akretschmer> ??srf
18:13 < rtfm_please> For information about srf
18:13 < rtfm_please> see http://www.postgresql.org/docs/current/static/xfunc-sql.html#XFUNC-SQL-TABLE-FUNCTIONS
18:13 < rtfm_please> or http://www.varlena.com/GeneralBits/26



Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: Question on returning Rows in a stored proc

From
Alan Hodgson
Date:
On Tuesday 24 March 2009, Richard Sickler <richard.sickler@avagotech.com>
wrote:
> real, etc.  But if I wanted to return the results of something like a
> query, (e.g. SELECT * FROM foo), how would I do that?
>

Look in the docs for set returning functions.

--
Even a sixth-grader can figure out that you can’t borrow money to pay off
your debt