You seek a Postgres function that returns a virtual table with custom content, boasting an unknown number of rows and three columns. You encounter difficulties locating the appropriate syntax and require assistance in crafting the function.
Utilize the following syntax to construct the desired function:
CREATE OR REPLACE FUNCTION f_foo() -- (open_id numeric) -- parameter not used RETURNS TABLE (a int, b int, c int) AS $func$ BEGIN RETURN QUERY VALUES (1,2,3) , (3,4,5) , (3,4,5) ; END $func$ LANGUAGE plpgsql IMMUTABLE ROWS 3;
Key Points:
Alternatives:
VALUES (1,2,3), (3,4,5), (3,4,5)
CREATE OR REPLACE FUNCTION f_foo() RETURNS TABLE (a int, b int, c int) AS $func$ VALUES (1, 2, 3) , (3, 4, 5) , (3, 4, 5); $func$ LANGUAGE sql IMMUTABLE ROWS 3;
The above is the detailed content of How to Create a Postgres Function Returning a Virtual Table with Multiple Rows?. For more information, please follow other related articles on the PHP Chinese website!