'how to return multiple result set in postgres, currently i am using refcursor for that . What would be the best solution in this scenario?
Hi I am using MySQL as my current dB but now we are switching it to postgres can anyone know how to write SPs in postgres and how can we return multiple data set in the postgres same as we return the multiple dataset from a Sp with n tables
CREATE OR REPLACE FUNCTION multipleresultset()
RETURNS SETOF refcursor AS
$BODY$
DECLARE
ref1 refcursor := 'cursor1';
ref2 refcursor := 'cursor2';
BEGIN open ref1 FOR SELECT * FROM table1;
RETURN NEXT ref1;
open ref2 FOR SELECT * FROM table2;
RETURN NEXT ref2;
--RETURN;END;$BODY$
LANGUAGE 'plpgsql';
begin;
select * from multipleresultset();
FETCH ALL in "cursor1";
FETCH ALL in "cursor2";
commit;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
