diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2018-01-10 16:39:13 -0500 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2018-01-10 16:39:13 -0500 |
commit | 511585417079b7d52211e09b20de0e0981b6eaa6 (patch) | |
tree | 0c7d6f791a4ea5e1f0de8224ebc48f6691b08bf6 | |
parent | b48b2f8793ef256d19274b4ef6ff587fd47ab553 (diff) | |
download | postgresql-511585417079b7d52211e09b20de0e0981b6eaa6.tar.gz postgresql-511585417079b7d52211e09b20de0e0981b6eaa6.zip |
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.
-rw-r--r-- | src/test/regress/expected/plpgsql.out | 24 | ||||
-rw-r--r-- | src/test/regress/sql/plpgsql.sql | 22 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index 4783807ae04..4f9501db008 100644 --- 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 768270d4676..3914651bf6d 100644 --- 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; |