A psql-function (sp_some_function) returns 2 cursors:
create or replace function sp_some_function() RETURNS SETOF REFCURSOR
as
$BODY$
declare
c_one refcursor := 'one' ;
c_two refcursor := 'two' ;
begin
open c_one for
select *
from TABLE_1;
return next c_one ;
open c_two for
select *
from TABLE_2;
return next c_two ;
return;
end
$BODY$
LANGUAGE PLPGSQL
I want to see what data each of the 2 cursors "contains".
To this end I wrote the following script:
DO $$
BEGIN
select sp_some_function();
FETCH ALL IN "one";
FETCH ALL IN "two";
END;
$$;
Running the script results in the following error message:
ERROR: "one" is not a known variable
I also tried the following:
DO $$
BEGIN
select sp_some_function();
FETCH ALL IN c_one;
FETCH ALL IN c_two;
END;
$$;
This resulted in the following error message:
ERROR: c_one is not a known variable
Finally, I tried the following:
create or replace function sp_some_function() RETURNS SETOF REFCURSOR
as
$BODY$
declare
c_one refcursor := 'one' ;
c_two refcursor := 'two' ;
begin
open c_one for
select *
from TABLE_1;
FETCH ALL IN c_one;
return next c_one ;
open c_two for
select *
from TABLE_2;
FETCH ALL IN c_two;
return next c_two ;
return;
end
$BODY$
LANGUAGE PLPGSQL
This didn't work either.
... How can I get the content of the two cursors?