Re: Functions returning multiple rowsets - Mailing list pgsql-general

From Thom Brown
Subject Re: Functions returning multiple rowsets
Date
Msg-id bddc86150909290548h3eb06c31k92ec609ea896f68d@mail.gmail.com
Whole thread Raw
In response to Re: Functions returning multiple rowsets  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-general
2009/9/28 Merlin Moncure <mmoncure@gmail.com>


with s as (select * from two_sets()),
foo as (select unnest(_foos) from s),
bar as (select unnest(_bars) from s)
select
 (select count(*) from foo) as no_foos,
 (select count(*) from bar) as no_bars;

merlin

I can see this working as we will be using 8.4.1, although it does seem rather unintuitive and clumsy.  I can see there's no straightforward way of achieving multiple result sets in the output.  I would have hoped for something like "returns record[]" to denote an array of records or "returns setof table" where table would be a parent database object of every other table.  I can work around this problem though, but I imagine it is something many people coming from MSSQL might be looking for.

As for seeking 2 result sets from code without any clever processing, you can just write as many queries as you want in PHP, and the results come out separate result sets in the result array. (e.g. $results[0] = first query, $results[1] = second query etc)

Thanks for the explanation Merlin.

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: Delphi connection ?
Next
From: Sam Mason
Date:
Subject: Re: query is taking longer time after a while