Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5115854

Browse files
committed
Add tests for PL/pgSQL returning unnamed portals as refcursor
Existing tests only covered returning explicitly named portals asrefcursor. The unnamed cursor case was recently broken without a testfailing.
1 parentb48b2f8 commit5115854

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

‎src/test/regress/expected/plpgsql.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,30 @@ drop function sp_id_user(text);
22422242
--
22432243
create table rc_test (a int, b int);
22442244
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+
22452269
create function return_refcursor(rc refcursor) returns refcursor as $$
22462270
begin
22472271
open rc for select a from rc_test;

‎src/test/regress/sql/plpgsql.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,28 @@ copy rc_test from stdin;
19101910
5001000
19111911
\.
19121912

1913+
createfunctionreturn_unnamed_refcursor() returns refcursoras $$
1914+
declare
1915+
rc refcursor;
1916+
begin
1917+
open rc forselect afrom rc_test;
1918+
return rc;
1919+
end
1920+
$$ language plpgsql;
1921+
1922+
createfunctionuse_refcursor(rc refcursor) returnsintas $$
1923+
declare
1924+
rc refcursor;
1925+
x record;
1926+
begin
1927+
rc := return_unnamed_refcursor();
1928+
fetch nextfrom rc into x;
1929+
returnx.a;
1930+
end
1931+
$$ language plpgsql;
1932+
1933+
select use_refcursor(return_unnamed_refcursor());
1934+
19131935
createfunctionreturn_refcursor(rc refcursor) returns refcursoras $$
19141936
begin
19151937
open rc forselect afrom rc_test;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp