From bf2efc55da9a1a33da32fa383db9db2f2c49b2cb Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 16 Nov 2019 20:00:19 -0500 Subject: 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 --- src/test/regress/expected/rules.out | 12 ++++++++++++ src/test/regress/sql/rules.sql | 2 ++ 2 files changed, 14 insertions(+) (limited to 'src/test') diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 14e72143468..abe3a43cd27 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -3025,6 +3025,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 diff --git a/src/test/regress/sql/rules.sql b/src/test/regress/sql/rules.sql index a042e595469..b7d7f434b6a 100644 --- a/src/test/regress/sql/rules.sql +++ b/src/test/regress/sql/rules.sql @@ -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 -- cgit v1.2.3