My requirement is that I want to create a generic function where I can pass any other function and its params and it should return appropriate output (i.e It may be a table result or single result etc.) and it should be with in single statement there.
This Is what I have searched and tried but I don't want to run any multiple statements.
CREATE FUNCTION CustomerWithOrdersByState() RETURNS SETOF refcursor AS $$
DECLARE
ref1 refcursor; -- Declare cursor variables
ref2 refcursor;
BEGIN
OPEN ref1 FOR SELECT * FROM "table1" limit 10;
RETURN NEXT ref1;
OPEN ref2 FOR SELECT * FROM "table2" limit 10;
RETURN NEXT ref2;
END;
$$ LANGUAGE plpgsql;
==================================================================
begin;
select * from CustomerWithOrdersByState();
FETCH ALL FROM "<unnamed portal 31>";
-- FETCH ALL FROM "<unnamed portal 30>";
commit;
I am using Postgres 11.4 version..
fetch all from...part manually.