1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Fix yet another corner case in dumping rules/views with USING clauses.

ruleutils.c tries to cope with additions/deletions/renamings of columns in
tables referenced by views, by means of adding machine-generated aliases to
the printed form of a view when needed to preserve the original semantics.
A recent blog post by Marko Tiikkaja pointed out a case I'd missed though:
if one input of a join with USING is itself a join, there is nothing to
stop the user from adding a column of the same name as the USING column to
whichever side of the sub-join didn't provide the USING column.  And then
there'll be an error when the view is re-parsed, since now the sub-join
exposes two columns matching the USING specification.  We were catching a
lot of related cases, but not this one, so add some logic to cope with it.

Back-patch to 9.3, which is the first release that makes any serious
attempt to cope with such cases (cf commit 2ffa740be and follow-ons).
This commit is contained in:
Tom Lane
2014-05-01 20:22:39 -04:00
parent b72e90bc31
commit e31193d495
3 changed files with 90 additions and 11 deletions

View File

@@ -1298,6 +1298,40 @@ select pg_get_viewdef('vv5', true);
JOIN tt10 USING (x);
(1 row)
--
-- Another corner case is that we might add a column to a table below a
-- JOIN USING, and thereby make the USING column name ambiguous
--
create table tt11 (x int, y int);
create table tt12 (x int, z int);
create table tt13 (z int, q int);
create view vv6 as select x,y,z,q from
(tt11 join tt12 using(x)) join tt13 using(z);
select pg_get_viewdef('vv6', true);
pg_get_viewdef
---------------------------
SELECT tt11.x, +
tt11.y, +
tt12.z, +
tt13.q +
FROM tt11 +
JOIN tt12 USING (x) +
JOIN tt13 USING (z);
(1 row)
alter table tt11 add column z int;
select pg_get_viewdef('vv6', true);
pg_get_viewdef
------------------------------
SELECT tt11.x, +
tt11.y, +
tt12.z, +
tt13.q +
FROM tt11 tt11(x, y, z_1)+
JOIN tt12 USING (x) +
JOIN tt13 USING (z);
(1 row)
-- clean up all the random objects we made above
set client_min_messages = warning;
DROP SCHEMA temp_view_test CASCADE;

View File

@@ -417,6 +417,24 @@ alter table tt9 drop column xx;
select pg_get_viewdef('vv5', true);
--
-- Another corner case is that we might add a column to a table below a
-- JOIN USING, and thereby make the USING column name ambiguous
--
create table tt11 (x int, y int);
create table tt12 (x int, z int);
create table tt13 (z int, q int);
create view vv6 as select x,y,z,q from
(tt11 join tt12 using(x)) join tt13 using(z);
select pg_get_viewdef('vv6', true);
alter table tt11 add column z int;
select pg_get_viewdef('vv6', true);
-- clean up all the random objects we made above
set client_min_messages = warning;
DROP SCHEMA temp_view_test CASCADE;