是否可以从 Postgres 函数返回多个结果集,例如在 MSSQL 中:
CREATE PROCEDURE test AS SELECT * FROM first_table SELECT * FROM second_table
自 PostgreSQL 8.3 以来,出现了一种更简单的方法:
CREATE FUNCTION test() RETURNS SETOF first_table AS $func$ BEGIN RETURN QUERY SELECT * FROM first_table; RETURN QUERY SELECT * FROM second_table; -- has to return same rowtype as first_table! END $func$ LANGUAGE plpgsql;
称呼:
SELECT * FROM test();