pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
FUNCTION returing multiple rows
2+ messages / 2 participants
[nested] [flat]

* FUNCTION returing multiple rows
@ 2001-01-02 21:15  Brett Schwarz <schwarz@PacketVideo.COM>
  0 siblings, 1 reply; 2+ messages in thread

From: Brett Schwarz @ 2001-01-02 21:15 UTC (permalink / raw)
  To: pgsql-sql

I have seen in the postings that it is not possible to return multiple rows
from a function.

However, when I look at the programmers guide (Ch. 4), it almost leads me to
believe otherwise:

---------------------8<---------------------------------------------------
The following more interesting example takes a single argument of type EMP,
and retrieves multiple results: 

select function hobbies (EMP) returns set of HOBBIES
    as 'select (HOBBIES.all) from HOBBIES
        where $1.name = HOBBIES.person'
    language 'sql';
  
---------------------8<---------------------------------------------------


I know that it only says 'multiple results' but with the 'HOBBIES.all', it
almost leads me to believe that it is retrieving all of the fields. Is 'all'
a keyword, or is this just one field in HOBBIES?

Also, is there any type of function return multiple rows (plpgsql, pltcl,
etc)?

If not, then is there anyway to fake it out to do this. Could I concatenate
the fields together to form one field per row. This would look like multiple
results of 1 field to PG. Also, if I did this, is there a delimiter I should
use?

for example:

select field1 || ':' || field2 || ':' || field3 from some_table;

Where ":" is the delimiter to send back.

Sorry for this question, but I am porting over an app from Oracle, and they
do not want to change the java code that calls this; so I need to make this
work somehow.

thanks,

--brett




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: FUNCTION returing multiple rows
@ 2001-01-03 05:01  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Brett Schwarz <schwarz@PacketVideo.COM>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2001-01-03 05:01 UTC (permalink / raw)
  To: Brett Schwarz <schwarz@PacketVideo.COM>; +Cc: pgsql-sql

Brett Schwarz <schwarz@PacketVideo.COM> writes:
> However, when I look at the programmers guide (Ch. 4), it almost leads me to
> believe otherwise:

> The following more interesting example takes a single argument of type EMP,
> and retrieves multiple results: 
> select function hobbies (EMP) returns set of HOBBIES
>     as 'select (HOBBIES.all) from HOBBIES
>         where $1.name = HOBBIES.person'
>     language 'sql';

This bit of the docs seems not to have been updated since PostQuel days.
The ".all" syntax is definitely out of date --- ".*" is the SQL
equivalent.  There is a descendant of this example in the current
regression tests:

CREATE FUNCTION hobbies(person)
   RETURNS setof hobbies_r 
   AS 'select * from hobbies_r where person = $1.name'
   LANGUAGE 'sql';

(Note that `person' is being used in two ways here, first as a datatype
and then as a field name --- not the least confusing example I could
have thought of...)

> Also, is there any type of function return multiple rows (plpgsql, pltcl,
> etc)?

In 7.0 and prior releases, *only* SQL functions can return multiple
rows.  The 7.1 function manager removes that hardwired assumption,
but in 7.1 the plpgsql, pltcl, plperl function language handlers don't
take advantage of the capability --- so the current state of affairs
is that you can do it in SQL or C functions only.  Hopefully this will
be improved in future releases.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-01-03 05:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-01-02 21:15 FUNCTION returing multiple rows Brett Schwarz <schwarz@PacketVideo.COM>
2001-01-03 05:01 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox