Pavel Stehule wrote, and Tom Lane committed patch which ads new syntax for set-returning functions: “RETURNS TABLE".
Commit was on 18th of July, and the message was:
Implement SQL-spec RETURNS TABLE syntax for functions. (Unlike the original submission, this patch treats TABLE output parameters as being entirely equivalent to OUT parameters -- tgl) Pavel Stehule
As you can tell from commit-log, new synatax doesn't give you any new functionality – it's just a syntactic sugar atop existing features.
But, I have to admit that it's a pretty tasty sugar:
CREATE FUNCTION test(max_i INT4) RETURNS TABLE (i INT4, double_i INT8) as $$ BEGIN FOR i IN SELECT generate_series(1, max_i) LOOP double_i := i * 2; RETURN next; END LOOP; RETURN; END; $$ language plpgsql;
Of course the same could be done using “OUT" parameters:
CREATE FUNCTION test(IN max_i INT4, OUT i INT4, OUT double_i INT8) RETURNS SETOF RECORD as $$ BEGIN FOR i IN SELECT generate_series(1, max_i) LOOP double_i := i * 2; RETURN next; END LOOP; RETURN; END; $$ language plpgsql;
but I like “RETURNS TABLE" better than out parameters. It's shorter and more readable. Good job.