git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b48b2f8)
Add tests for PL/pgSQL returning unnamed portals as refcursor
2018年1月10日 21:39:13 +0000 (16:39 -0500)
2018年1月10日 21:39:13 +0000 (16:39 -0500)
Existing tests only covered returning explicitly named portals as
refcursor. The unnamed cursor case was recently broken without a test
failing.


diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out
index 4783807ae04361af54b8cc54a9b13432161217df..4f9501db00877494039b95b439adc5a6bb9337ca 100644 (file)
--- a/src/test/regress/expected/plpgsql.out
+++ b/src/test/regress/expected/plpgsql.out
@@ -2242,6 +2242,30 @@ drop function sp_id_user(text);
--
create table rc_test (a int, b int);
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 $$
begin
open rc for select a from rc_test;
diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql
index 768270d46765c8afe105a6694898ae13431103c7..3914651bf6d2505375faf3da26838f6636db42d2 100644 (file)
--- a/src/test/regress/sql/plpgsql.sql
+++ b/src/test/regress/sql/plpgsql.sql
@@ -1910,6 +1910,28 @@ copy rc_test from stdin;
500 1000
\.
+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());
+
create function return_refcursor(rc refcursor) returns refcursor as $$
begin
open rc for select a from rc_test;
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /