returning dynamic record

Started by Nicholas Walkerover 18 years ago3 messagesgeneral
Jump to latest
#1Nicholas Walker
nick@walkerdatanet.com

Just wondering, if it is possible to do the following

create function foo() RETURNS Record(int, varchar, int)

then inside of the function return a set int, varchar, int.

Then be able to call the function

select * From foo()

instead of having to write

select * from foo() as (int, varchar, int)

or declaring a type?

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Nicholas Walker (#1)
Re: returning dynamic record

nick <nick@walkerdatanet.com> writes:

Just wondering, if it is possible to do the following
create function foo() RETURNS Record(int, varchar, int)

OUT parameters (in reasonably recent PG releases).

regression=# create function foo (f1 out int, f2 out varchar, f3 out int) as
$$ select 42, 'foo'::varchar, 43 $$ language sql;
CREATE FUNCTION
regression=# select * from foo();
f1 | f2 | f3
----+-----+----
42 | foo | 43
(1 row)

regards, tom lane

#3Reg Me Please
regmeplease@gmail.com
In reply to: Tom Lane (#2)
Re: returning dynamic record

Il Wednesday 07 November 2007 06:35:55 Tom Lane ha scritto:

nick <nick@walkerdatanet.com> writes:

Just wondering, if it is possible to do the following
create function foo() RETURNS Record(int, varchar, int)

OUT parameters (in reasonably recent PG releases).

regression=# create function foo (f1 out int, f2 out varchar, f3 out int)
as $$ select 42, 'foo'::varchar, 43 $$ language sql;
CREATE FUNCTION
regression=# select * from foo();
f1 | f2 | f3
----+-----+----
42 | foo | 43
(1 row)

regards, tom lane

Maybe

create function foo (f1 out int, f2 out varchar, f3 out int)
returns setof record as $body$
...

will return the set.

--
Reg me Please