diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/plpgsql.out | 19 | ||||
| -rw-r--r-- | src/test/regress/sql/plpgsql.sql | 20 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index 08e42f17dc2..cdc519256a7 100644 --- a/src/test/regress/expected/plpgsql.out +++ b/src/test/regress/expected/plpgsql.out @@ -3482,6 +3482,9 @@ declare c2 cursor for select * from generate_series(41,43) i; begin + -- assign portal names to cursors to get stable output + c := 'c'; + c2 := 'c2'; for r in c(5,7) loop raise notice '% from %', r.i, c; end loop; @@ -3624,6 +3627,22 @@ select * from forc_test; (10 rows) drop function forc01(); +-- it's okay to re-use a cursor variable name, even when bound +do $$ +declare cnt int := 0; + c1 cursor for select * from forc_test; +begin + for r1 in c1 loop + declare c1 cursor for select * from forc_test; + begin + for r2 in c1 loop + cnt := cnt + 1; + end loop; + end; + end loop; + raise notice 'cnt = %', cnt; +end $$; +NOTICE: cnt = 100 -- fail because cursor has no query bound to it create or replace function forc_bad() returns void as $$ declare diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql index 588c3310337..9a53b150814 100644 --- a/src/test/regress/sql/plpgsql.sql +++ b/src/test/regress/sql/plpgsql.sql @@ -2929,6 +2929,9 @@ declare c2 cursor for select * from generate_series(41,43) i; begin + -- assign portal names to cursors to get stable output + c := 'c'; + c2 := 'c2'; for r in c(5,7) loop raise notice '% from %', r.i, c; end loop; @@ -3002,6 +3005,23 @@ select * from forc_test; drop function forc01(); +-- it's okay to re-use a cursor variable name, even when bound + +do $$ +declare cnt int := 0; + c1 cursor for select * from forc_test; +begin + for r1 in c1 loop + declare c1 cursor for select * from forc_test; + begin + for r2 in c1 loop + cnt := cnt + 1; + end loop; + end; + end loop; + raise notice 'cnt = %', cnt; +end $$; + -- fail because cursor has no query bound to it create or replace function forc_bad() returns void as $$ |
