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