calling a function that takes a row type and returns a set of rows

From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: calling a function that takes a row type and returns a set of rows
Date: 2008-10-10 19:22:14
Message-ID: 603c8f070810101222h2745f90bg712d0745dd68c68f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

So, say I have something like this - the actual example is something a
bit more useful:

CREATE TABLE foo (a integer, b integer);
INSERT INTO foo VALUES (1, 1); -- must have some data to generate the failure

CREATE FUNCTION bar (foo) RETURNS SETOF foo AS $$
DECLARE
f foo;
BEGIN
f.a := 1;
RETURN NEXT f;
f.a := 2;
RETURN NEXT f;
END
$$ LANGUAGE plpgsql;

I can't find any legal way of calling this function.

SELECT bar(f) FROM foo f;
ERROR: set-valued function called in context that cannot accept a set

SELECT * FROM foo f, bar(f);
ERROR: function expression in FROM may not refer to other relations
of same query level

Any help appreciated.

Thanks,

...Robert

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2008-10-10 20:01:04 Re: calling a function that takes a row type and returns a set of rows
Previous Message postgres Emanuel CALVO FRANCO 2008-10-10 18:01:00 Re: Opteron vs. Xeon performance differences