summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-03-23 04:22:37 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-03-23 04:22:37 +0000
commit4fb92718be654b38652dfe893d075f3862e84eae (patch)
tree5257cc914a9c9ea581b3854d40b2815692113176 /src/test
parent19956e0d5388b11a1cc3eaf2dbf628aa531ce331 (diff)
downloadpostgresql-4fb92718be654b38652dfe893d075f3862e84eae.tar.gz
Fix plpgsql to pass only one copy of any given plpgsql variable into a SQL
command or expression, rather than one copy for each textual occurrence as it did before. This might result in some small performance improvement, but the compelling reason to do it is that not doing so can result in unexpected grouping failures because the main SQL parser won't see different parameter numbers as equivalent. Add a regression test for the failure case. Per report from Robert Davidson.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/plpgsql.out18
-rw-r--r--src/test/regress/sql/plpgsql.sql15
2 files changed, 33 insertions, 0 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out
index e72383bbb7..6e6597dadb 100644
--- a/src/test/regress/expected/plpgsql.out
+++ b/src/test/regress/expected/plpgsql.out
@@ -2776,3 +2776,21 @@ NOTICE: 4 bb cc
(1 row)
+-- regression test: verify that multiple uses of same plpgsql datum within
+-- a SQL command all get mapped to the same $n parameter. The return value
+-- of the SELECT is not important, we only care that it doesn't fail with
+-- a complaint about an ungrouped column reference.
+create function multi_datum_use(p1 int) returns bool as $$
+declare
+ x int;
+ y int;
+begin
+ select into x,y unique1/p1, unique1/$1 from tenk1 group by unique1/p1;
+ return x = y;
+end$$ language plpgsql;
+select multi_datum_use(42);
+ multi_datum_use
+-----------------
+ t
+(1 row)
+
diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql
index a2d65817b1..19e145be65 100644
--- a/src/test/regress/sql/plpgsql.sql
+++ b/src/test/regress/sql/plpgsql.sql
@@ -2309,3 +2309,18 @@ end;
$proc$ language plpgsql;
select for_vect();
+
+-- regression test: verify that multiple uses of same plpgsql datum within
+-- a SQL command all get mapped to the same $n parameter. The return value
+-- of the SELECT is not important, we only care that it doesn't fail with
+-- a complaint about an ungrouped column reference.
+create function multi_datum_use(p1 int) returns bool as $$
+declare
+ x int;
+ y int;
+begin
+ select into x,y unique1/p1, unique1/$1 from tenk1 group by unique1/p1;
+ return x = y;
+end$$ language plpgsql;
+
+select multi_datum_use(42);