1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Further fix dumping of views that contain just VALUES(...).

It turns out that commit e9f1c01b7 missed a case: we must print a
VALUES clause in long format if get_query_def is given a resultDesc
that would require the query's output column name(s) to be different
from what the bare VALUES clause would produce.

This applies in case an ALTER ... RENAME COLUMN has been done to
a view that formerly could be printed in simple format, as shown
in the added regression test case.  It also explains bug #16119
from Dmitry Telpt, because it turns out that (unlike CREATE VIEW)
CREATE MATERIALIZED VIEW fails to apply any column aliases it's
given to the stored ON SELECT rule.  So to get them to be printed,
we have to account for the resultDesc renaming.  It might be worth
changing the matview code so that it creates the ON SELECT rule
with the correct aliases; but we'd still need these messy checks in
get_simple_values_rte to handle the case of a subsequent column
rename, so any such change would be just neatnik-ism not a bug fix.

Like the previous patch, back-patch to all supported branches.

Discussion: https://postgr.es/m/16119-e64823f30a45a754@postgresql.org
This commit is contained in:
Tom Lane
2019-11-16 20:00:19 -05:00
parent bbaa38e824
commit fcaf29d87a
3 changed files with 38 additions and 10 deletions

View File

@ -3023,6 +3023,18 @@ create view rule_v1 as values(1,2);
View definition:
VALUES (1,2);
alter table rule_v1 rename column column2 to q2;
\d+ rule_v1
View "public.rule_v1"
Column | Type | Collation | Nullable | Default | Storage | Description
---------+---------+-----------+----------+---------+---------+-------------
column1 | integer | | | | plain |
q2 | integer | | | | plain |
View definition:
SELECT "*VALUES*".column1,
"*VALUES*".column2 AS q2
FROM (VALUES (1,2)) "*VALUES*";
drop view rule_v1;
create view rule_v1(x) as values(1,2);
\d+ rule_v1

View File

@ -1047,6 +1047,8 @@ DROP TABLE rule_t1;
--
create view rule_v1 as values(1,2);
\d+ rule_v1
alter table rule_v1 rename column column2 to q2;
\d+ rule_v1
drop view rule_v1;
create view rule_v1(x) as values(1,2);
\d+ rule_v1