summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-11-09 02:36:59 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-11-09 02:36:59 +0000
commit2ace38d226246b83e5cc4d8f4063a82a485ddc95 (patch)
tree5ba7f075efde9d793b927253f28b5802c6806322 /src/test
parent39bd3fd1db6f3aa3764d4a1bebcd71c4e9c00281 (diff)
Fix WHERE CURRENT OF to work as designed within plpgsql. The argument
can be the name of a plpgsql cursor variable, which formerly was converted to $N before the core parser saw it, but that's no longer the case. Deal with plain name references to plpgsql variables, and add a regression test case that exposes the failure.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/plpgsql.out46
-rw-r--r--src/test/regress/sql/plpgsql.sql20
2 files changed, 66 insertions, 0 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out
index 534a60057dc..16b7907a2f7 100644
--- a/src/test/regress/expected/plpgsql.out
+++ b/src/test/regress/expected/plpgsql.out
@@ -3292,6 +3292,52 @@ select * from forc_test;
1000 | 20
(10 rows)
+-- same, with a cursor whose portal name doesn't match variable name
+create or replace function forc01() returns void as $$
+declare
+ c refcursor := 'fooled_ya';
+ r record;
+begin
+ open c for select * from forc_test;
+ loop
+ fetch c into r;
+ exit when not found;
+ raise notice '%, %', r.i, r.j;
+ update forc_test set i = i * 100, j = r.j * 2 where current of c;
+ end loop;
+end;
+$$ language plpgsql;
+select forc01();
+NOTICE: 100, 2
+NOTICE: 200, 4
+NOTICE: 300, 6
+NOTICE: 400, 8
+NOTICE: 500, 10
+NOTICE: 600, 12
+NOTICE: 700, 14
+NOTICE: 800, 16
+NOTICE: 900, 18
+NOTICE: 1000, 20
+ forc01
+--------
+
+(1 row)
+
+select * from forc_test;
+ i | j
+--------+----
+ 10000 | 4
+ 20000 | 8
+ 30000 | 12
+ 40000 | 16
+ 50000 | 20
+ 60000 | 24
+ 70000 | 28
+ 80000 | 32
+ 90000 | 36
+ 100000 | 40
+(10 rows)
+
drop function forc01();
-- fail because cursor has no query bound to it
create or replace function forc_bad() returns void as $$
diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql
index 51bfce2e0c1..c75f037cdbc 100644
--- a/src/test/regress/sql/plpgsql.sql
+++ b/src/test/regress/sql/plpgsql.sql
@@ -2689,6 +2689,26 @@ select forc01();
select * from forc_test;
+-- same, with a cursor whose portal name doesn't match variable name
+create or replace function forc01() returns void as $$
+declare
+ c refcursor := 'fooled_ya';
+ r record;
+begin
+ open c for select * from forc_test;
+ loop
+ fetch c into r;
+ exit when not found;
+ raise notice '%, %', r.i, r.j;
+ update forc_test set i = i * 100, j = r.j * 2 where current of c;
+ end loop;
+end;
+$$ language plpgsql;
+
+select forc01();
+
+select * from forc_test;
+
drop function forc01();
-- fail because cursor has no query bound to it