Skip to content

Commit 5115854

Browse files
committed
Add tests for PL/pgSQL returning unnamed portals as refcursor
Existing tests only covered returning explicitly named portals as refcursor. The unnamed cursor case was recently broken without a test failing.
1 parent b48b2f8 commit 5115854

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
500 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+
19131935
create function return_refcursor(rc refcursor) returns refcursor as $$
19141936
begin
19151937
open rc for select a from rc_test;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy