File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -2242,6 +2242,30 @@ drop function sp_id_user(text);
22422242--
22432243create table rc_test (a int, b int);
22442244copy rc_test from stdin;
2245+ create function return_unnamed_refcursor() returns refcursor as $$
2246+ declare
2247+ rc refcursor;
2248+ begin
2249+ open rc for select a from rc_test;
2250+ return rc;
2251+ end
2252+ $$ language plpgsql;
2253+ create function use_refcursor(rc refcursor) returns int as $$
2254+ declare
2255+ rc refcursor;
2256+ x record;
2257+ begin
2258+ rc := return_unnamed_refcursor();
2259+ fetch next from rc into x;
2260+ return x.a;
2261+ end
2262+ $$ language plpgsql;
2263+ select use_refcursor(return_unnamed_refcursor());
2264+ use_refcursor
2265+ ---------------
2266+ 5
2267+ (1 row)
2268+
22452269create function return_refcursor(rc refcursor) returns refcursor as $$
22462270begin
22472271 open rc for select a from rc_test;
Original file line number Diff line number Diff line change @@ -1910,6 +1910,28 @@ copy rc_test from stdin;
19101910500 1000
19111911\.
19121912
1913+ create function return_unnamed_refcursor () returns refcursor as $$
1914+ declare
1915+ rc refcursor;
1916+ begin
1917+ open rc for select a from rc_test;
1918+ return rc;
1919+ end
1920+ $$ language plpgsql;
1921+
1922+ create function use_refcursor (rc refcursor) returns int as $$
1923+ declare
1924+ rc refcursor;
1925+ x record;
1926+ begin
1927+ rc := return_unnamed_refcursor();
1928+ fetch next from rc into x;
1929+ return x .a ;
1930+ end
1931+ $$ language plpgsql;
1932+
1933+ select use_refcursor(return_unnamed_refcursor());
1934+
19131935create function return_refcursor (rc refcursor) returns refcursor as $$
19141936begin
19151937 open rc for select a from rc_test;
You can’t perform that action at this time.
0 commit comments