File tree 2 files changed +46
-0
lines changed
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);
2242
2242
--
2243
2243
create table rc_test (a int, b int);
2244
2244
copy 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
+
2245
2269
create function return_refcursor(rc refcursor) returns refcursor as $$
2246
2270
begin
2247
2271
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;
1910
1910
500 1000
1911
1911
\.
1912
1912
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
+
1913
1935
create function return_refcursor (rc refcursor) returns refcursor as $$
1914
1936
begin
1915
1937
open rc for select a from rc_test;
You can’t perform that action at this time.
0 commit comments