|
|
@ -2242,6 +2242,30 @@ drop function sp_id_user(text); |
|
|
|
-- |
|
|
|
-- |
|
|
|
create table rc_test (a int, b int); |
|
|
|
create table rc_test (a int, b int); |
|
|
|
copy rc_test from stdin; |
|
|
|
copy rc_test from stdin; |
|
|
|
|
|
|
|
create function return_unnamed_refcursor() returns refcursor as $$ |
|
|
|
|
|
|
|
declare |
|
|
|
|
|
|
|
rc refcursor; |
|
|
|
|
|
|
|
begin |
|
|
|
|
|
|
|
open rc for select a from rc_test; |
|
|
|
|
|
|
|
return rc; |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
$$ language plpgsql; |
|
|
|
|
|
|
|
create function use_refcursor(rc refcursor) returns int as $$ |
|
|
|
|
|
|
|
declare |
|
|
|
|
|
|
|
rc refcursor; |
|
|
|
|
|
|
|
x record; |
|
|
|
|
|
|
|
begin |
|
|
|
|
|
|
|
rc := return_unnamed_refcursor(); |
|
|
|
|
|
|
|
fetch next from rc into x; |
|
|
|
|
|
|
|
return x.a; |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
$$ language plpgsql; |
|
|
|
|
|
|
|
select use_refcursor(return_unnamed_refcursor()); |
|
|
|
|
|
|
|
use_refcursor |
|
|
|
|
|
|
|
--------------- |
|
|
|
|
|
|
|
5 |
|
|
|
|
|
|
|
(1 row) |
|
|
|
|
|
|
|
|
|
|
|
create function return_refcursor(rc refcursor) returns refcursor as $$ |
|
|
|
create function return_refcursor(rc refcursor) returns refcursor as $$ |
|
|
|
begin |
|
|
|
begin |
|
|
|
open rc for select a from rc_test; |
|
|
|
open rc for select a from rc_test; |
|
|
|