1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Fix ruleutils.c's dumping of whole-row Vars in ROW() and VALUES() contexts.

Normally ruleutils prints a whole-row Var as "foo.*".  We already knew that
that doesn't work at top level of a SELECT list, because the parser would
treat the "*" as a directive to expand the reference into separate columns,
not a whole-row Var.  However, Joshua Yanovski points out in bug #13776
that the same thing happens at top level of a ROW() construct; and some
nosing around in the parser shows that the same is true in VALUES().
Hence, apply the same workaround already devised for the SELECT-list case,
namely to add a forced cast to the appropriate rowtype in these cases.
(The alternative of just printing "foo" was rejected because it is
difficult to avoid ambiguity against plain columns named "foo".)

Back-patch to all supported branches.
This commit is contained in:
Tom Lane
2015-11-15 14:41:09 -05:00
parent 7d9a4737c2
commit 7745bc352a
3 changed files with 139 additions and 5 deletions

View File

@ -1384,6 +1384,97 @@ select * from tt14v;
foo | | quux
(1 row)
-- check display of whole-row variables in some corner cases
create type nestedcomposite as (x int8_tbl);
create view tt15v as select row(i)::nestedcomposite from int8_tbl i;
select * from tt15v;
row
------------------------------------------
("(123,456)")
("(123,4567890123456789)")
("(4567890123456789,123)")
("(4567890123456789,4567890123456789)")
("(4567890123456789,-4567890123456789)")
(5 rows)
select pg_get_viewdef('tt15v', true);
pg_get_viewdef
------------------------------------------------------
SELECT ROW(i.*::int8_tbl)::nestedcomposite AS "row"+
FROM int8_tbl i;
(1 row)
select row(i.*::int8_tbl)::nestedcomposite from int8_tbl i;
row
------------------------------------------
("(123,456)")
("(123,4567890123456789)")
("(4567890123456789,123)")
("(4567890123456789,4567890123456789)")
("(4567890123456789,-4567890123456789)")
(5 rows)
create view tt16v as select * from int8_tbl i, lateral(values(i)) ss;
select * from tt16v;
q1 | q2 | column1
------------------+-------------------+--------------------------------------
123 | 456 | (123,456)
123 | 4567890123456789 | (123,4567890123456789)
4567890123456789 | 123 | (4567890123456789,123)
4567890123456789 | 4567890123456789 | (4567890123456789,4567890123456789)
4567890123456789 | -4567890123456789 | (4567890123456789,-4567890123456789)
(5 rows)
select pg_get_viewdef('tt16v', true);
pg_get_viewdef
-------------------------------------------
SELECT i.q1, +
i.q2, +
ss.column1 +
FROM int8_tbl i, +
LATERAL ( VALUES (i.*::int8_tbl)) ss;
(1 row)
select * from int8_tbl i, lateral(values(i.*::int8_tbl)) ss;
q1 | q2 | column1
------------------+-------------------+--------------------------------------
123 | 456 | (123,456)
123 | 4567890123456789 | (123,4567890123456789)
4567890123456789 | 123 | (4567890123456789,123)
4567890123456789 | 4567890123456789 | (4567890123456789,4567890123456789)
4567890123456789 | -4567890123456789 | (4567890123456789,-4567890123456789)
(5 rows)
create view tt17v as select * from int8_tbl i where i in (values(i));
select * from tt17v;
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
select pg_get_viewdef('tt17v', true);
pg_get_viewdef
---------------------------------------------
SELECT i.q1, +
i.q2 +
FROM int8_tbl i +
WHERE (i.* IN ( VALUES (i.*::int8_tbl)));
(1 row)
select * from int8_tbl i where i.* in (values(i.*::int8_tbl));
q1 | q2
------------------+-------------------
123 | 456
123 | 4567890123456789
4567890123456789 | 123
4567890123456789 | 4567890123456789
4567890123456789 | -4567890123456789
(5 rows)
-- clean up all the random objects we made above
set client_min_messages = warning;
DROP SCHEMA temp_view_test CASCADE;

View File

@ -469,6 +469,24 @@ alter table tt14t drop column f3;
select pg_get_viewdef('tt14v', true);
select * from tt14v;
-- check display of whole-row variables in some corner cases
create type nestedcomposite as (x int8_tbl);
create view tt15v as select row(i)::nestedcomposite from int8_tbl i;
select * from tt15v;
select pg_get_viewdef('tt15v', true);
select row(i.*::int8_tbl)::nestedcomposite from int8_tbl i;
create view tt16v as select * from int8_tbl i, lateral(values(i)) ss;
select * from tt16v;
select pg_get_viewdef('tt16v', true);
select * from int8_tbl i, lateral(values(i.*::int8_tbl)) ss;
create view tt17v as select * from int8_tbl i where i in (values(i));
select * from tt17v;
select pg_get_viewdef('tt17v', true);
select * from int8_tbl i where i.* in (values(i.*::int8_tbl));
-- clean up all the random objects we made above
set client_min_messages = warning;
DROP SCHEMA temp_view_test CASCADE;