Re: Multiple return 'columns' from postgre pl/pgsql - Mailing list pgsql-novice

From Tom Lane
Subject Re: Multiple return 'columns' from postgre pl/pgsql
Date
Msg-id 14372.1092061391@sss.pgh.pa.us
Whole thread Raw
In response to Re: Multiple return 'columns' from postgre pl/pgsql  (Steve Tucknott <steve@retsol.co.uk>)
Responses Re: Multiple return 'columns' from postgre pl/pgsql
List pgsql-novice
Steve Tucknott <steve@retsol.co.uk> writes:
> Does the 'rowtype' have to exist as a definition in the database?

In the form I showed, yes.

> Would returning a record type work -

Only if you're prepared to specify the actual record type in the calling
query.  The point is that in

    select * from myfunc(...);

the parser has to have some way of understanding what * expands to,
and it needs the info in advance of calling the function.  So you
either need to return a named rowtype, or return record and specify
what you're expecting in the call.  From memory it's something like

    select * from myfunc(...) AS (f1 int, f2 text, ...);

but see the docs.  In practice I think the named rowtype is easier in
99% of cases.  The returns-record case is really meant for functions
that can actually return different rowtypes depending on the parameters
they are given, like dblink() does.  If you're thinking of doing something
like that, you probably shouldn't be asking about it on the novice list ;-)

            regards, tom lane

pgsql-novice by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Design question regarding arrays
Next
From: "Sean Davis"
Date:
Subject: Re: Design question regarding arrays