"RETURNS SETOF" function question

From: "Kynn Jones" <kynnjo(at)gmail(dot)com>
To: "pgsql-general General" <pgsql-general(at)postgresql(dot)org>
Subject: "RETURNS SETOF" function question
Date: 2008-02-24 22:19:29
Message-ID: c2350ba40802241419qeaec89k82e1c020f90b819f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joris Dobbelsteen 2008-02-24 22:35:41 Planner: rows=1 after "similar to" where condition.
Previous Message Joris Dobbelsteen 2008-02-24 21:59:10 More formal definition of functions in documentation