Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,


I am a newbie to PostgreSQL. I want to return multiple tables using function in PostgreSQL just like writing multiple select statement in MSSQL stored procedure.

Can anyone suggest me how to do it please?

Thank u to all...
Posted

1 solution

This is not purely supported by PostgreSQL (as far as I know), you can get results combined if they return the same row type. You can do that either through a UNION ALL or a function like following-
SQL
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

Reference: http://stackoverflow.com/a/7748232[^]

hope, it helps ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900