"RETURNS SETOF" function question - Mailing list pgsql-general

From Kynn Jones
Subject "RETURNS SETOF" function question
Date
Msg-id c2350ba40802241419qeaec89k82e1c020f90b819f@mail.gmail.com
Whole thread Raw
Responses Re: "RETURNS SETOF" function question
List pgsql-general

Suppose that stored procedure foo has the signature:

  foo( text, text ) RETURNS SETOF text

Also, I have some table bar, and that column bar.baz is of type text.

Now, I'd like to run something like

  SELECT foo( "frobozz", baz ) FROM bar;

If I try this psql complains that I'm trying to execute a set-valued function in the wrong context.

But the intention of this invalid statement is to apply foo( "frobozz", ? ) once for each row of bar, replacing ? each time with the row's value of baz, and concatenate all the returned tables to produce the final result.  (In general, the number of rows resulting from this application has no relation to the number of rows in bar; i.e. it can be less than, equal to, or greater than this number.)

What must I do to get the desired behavior?

TIA!

kynn

pgsql-general by date:

Previous
From: "hernan gonzalez"
Date:
Subject: Re: text and bytea
Next
From: "Joris Dobbelsteen"
Date:
Subject: More formal definition of functions in documentation