Thread: concatenating setof functions

concatenating setof functions

From
"Frederick Ross"
Date:
I suspect I am missing a much cleaner way of doing this, but say I
have a function which returns a setof integer, i.e.,

create or replace function testfunc (integer) returns setof integer as $$
declare
     i alias for $1;
begin
     return next i;
     return next i+100;
     return;
end
$$ language plpgsql;

I know I can call this as: select * from twohundreds(3);

But say I have a table with an integer column.  If I had a pure SQL
function, I could call

select twohundreds(i) from table;

and get a properly concatenated list of the rows resulting from
applying twohundreds to each row of table.  This is deprecated
according to the documentation, and it doesn't work at all with
PLPGSQL, so how should I go about doing it?

--
Frederick Ross
Graduate Fellow, (|Siggia> + |McKinney>)/sqrt(2) Lab
The Rockefeller University
Je ne suis pas Fred Cross!

Re: concatenating setof functions

From
Tom Lane
Date:
"Frederick Ross" <madhadron@gmail.com> writes:
> But say I have a table with an integer column.  If I had a pure SQL
> function, I could call
> select twohundreds(i) from table;
> and get a properly concatenated list of the rows resulting from
> applying twohundreds to each row of table.  This is deprecated
> according to the documentation, and it doesn't work at all with
> PLPGSQL, so how should I go about doing it?

I believe you can make an end-run around the implementation restriction
by creating a SQL-language function that's a wrapper around your plpgsql
function.

            regards, tom lane