mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-10 13:57:30 +08:00
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.
This commit is contained in:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user