From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: avoid the creating the type for setof |
Date: | 2011-12-30 14:48:30 |
Message-ID: | jdkivn$7m5$1@dough.gmane.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
John Fabiani wrote on 30.12.2011 15:26:
> Hi,
> I recall somewhere I saw a simple plpgsql function that returned a table with
> more than one record that did not use a defined type or a temp table ( at
> least I think I did). Is it possible to create such a function that will
> return more than one record and not require a record type or temp table?
>
> something like
>
> return setof record as
> return query select ...
>
> return
Sure:
create or replace function
returns table (f1 text, f2 integer)
as
$$
select col1, col2 from some table;
$$
language sql;
If you are using PL/pgSQL you need to use "RETURN QUERY SELECT ..." inside the function.
For more details see the examples in the manual:
http://www.postgresql.org/docs/current/static/sql-createfunction.html
http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING
Thomas
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2011-12-30 14:49:42 | Re: avoid the creating the type for setof |
Previous Message | John Fabiani | 2011-12-30 14:26:19 | avoid the creating the type for setof |