diff options
| author | Tom Lane | 2013-07-23 21:54:18 +0000 |
|---|---|---|
| committer | Tom Lane | 2013-07-23 21:55:04 +0000 |
| commit | ef655663c5069231e054c3514c3ee9b15b8a4f13 (patch) | |
| tree | 88f29f148d99ed2759a72b420ebc7c40cfb1db39 /src/test | |
| parent | bb686c9a865dc15a704e6a96367b3d7bfe79df6f (diff) | |
Further hacking on ruleutils' new column-alias-assignment code.
After further thought about implicit coercions appearing in a joinaliasvars
list, I realized that they represent an additional reason why we might need
to reference the join output column directly instead of referencing an
underlying column. Consider SELECT x FROM t1 LEFT JOIN t2 USING (x) where
t1.x is of type date while t2.x is of type timestamptz. The merged output
variable is of type timestamptz, but it won't go to null when t2 does,
therefore neither t1.x nor t2.x is a valid substitute reference.
The code in get_variable() actually gets this case right, since it knows
it shouldn't look through a coercion, but we failed to ensure that the
unqualified output column name would be globally unique. To fix, modify
the code that trawls for a dangerous situation so that it actually scans
through an unnamed join's joinaliasvars list to see if there are any
non-simple-Var entries.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/create_view.out | 28 | ||||
| -rw-r--r-- | src/test/regress/sql/create_view.sql | 13 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/test/regress/expected/create_view.out b/src/test/regress/expected/create_view.out index 8b45142967..23efff16ff 100644 --- a/src/test/regress/expected/create_view.out +++ b/src/test/regress/expected/create_view.out @@ -1243,6 +1243,34 @@ select pg_get_viewdef('vv4', true); FULL JOIN tt8 tt8y(x_1, z, z2) USING (x_1); (1 row) +-- Implicit coercions in a JOIN USING create issues similar to FULL JOIN +create table tt7a (x date, xx int, y int); +alter table tt7a drop column xx; +create table tt8a (x timestamptz, z int); +create view vv2a as +select * from (values(now(),2,3,now(),5)) v(a,b,c,d,e) +union all +select * from tt7a left join tt8a using (x), tt8a tt8ax; +select pg_get_viewdef('vv2a', true); + pg_get_viewdef +---------------------------------------------------------------- + SELECT v.a, + + v.b, + + v.c, + + v.d, + + v.e + + FROM ( VALUES (now(),2,3,now(),5)) v(a, b, c, d, e)+ + UNION ALL + + SELECT x AS a, + + tt7a.y AS b, + + tt8a.z AS c, + + tt8ax.x_1 AS d, + + tt8ax.z AS e + + FROM tt7a + + LEFT JOIN tt8a USING (x), + + tt8a tt8ax(x_1, z); +(1 row) + -- -- Also check dropping a column that existed when the view was made -- diff --git a/src/test/regress/sql/create_view.sql b/src/test/regress/sql/create_view.sql index 4fbd5a5e6f..234a4214b2 100644 --- a/src/test/regress/sql/create_view.sql +++ b/src/test/regress/sql/create_view.sql @@ -389,6 +389,19 @@ select pg_get_viewdef('vv2', true); select pg_get_viewdef('vv3', true); select pg_get_viewdef('vv4', true); +-- Implicit coercions in a JOIN USING create issues similar to FULL JOIN + +create table tt7a (x date, xx int, y int); +alter table tt7a drop column xx; +create table tt8a (x timestamptz, z int); + +create view vv2a as +select * from (values(now(),2,3,now(),5)) v(a,b,c,d,e) +union all +select * from tt7a left join tt8a using (x), tt8a tt8ax; + +select pg_get_viewdef('vv2a', true); + -- -- Also check dropping a column that existed when the view was made -- |
