mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Fix dumping of views that are just VALUES(...) but have column aliases.
The "simple" path for printing VALUES clauses doesn't work if we need
to attach nondefault column aliases, because there's noplace to do that
in the minimal VALUES() syntax. So modify get_simple_values_rte() to
detect nondefault aliases and treat that as a non-simple case. This
further exposes that the "non-simple" path never actually worked;
it didn't produce valid syntax. Fix that too. Per bug #12789 from
Curtis McEnroe, and analysis by Andrew Gierth.
Back-patch to all supported branches. Before 9.3, this also requires
back-patching the part of commit 092d7ded29
that created get_simple_values_rte() to begin with; inserting the extra
test into the old factorization of that logic would've been too messy.
This commit is contained in:
@ -2507,6 +2507,7 @@ select * from only t1_2;
|
||||
19
|
||||
(10 rows)
|
||||
|
||||
reset constraint_exclusion;
|
||||
-- test various flavors of pg_get_viewdef()
|
||||
select pg_get_viewdef('shoe'::regclass) as unpretty;
|
||||
unpretty
|
||||
@ -2678,3 +2679,56 @@ ALTER RULE "_RETURN" ON rule_v1 RENAME TO abc; -- ON SELECT rule cannot be renam
|
||||
ERROR: renaming an ON SELECT rule is not allowed
|
||||
DROP VIEW rule_v1;
|
||||
DROP TABLE rule_t1;
|
||||
--
|
||||
-- check display of VALUES in view definitions
|
||||
--
|
||||
create view rule_v1 as values(1,2);
|
||||
\d+ rule_v1
|
||||
View "public.rule_v1"
|
||||
Column | Type | Modifiers | Storage | Description
|
||||
---------+---------+-----------+---------+-------------
|
||||
column1 | integer | | plain |
|
||||
column2 | integer | | plain |
|
||||
View definition:
|
||||
VALUES (1,2);
|
||||
|
||||
drop view rule_v1;
|
||||
create view rule_v1(x) as values(1,2);
|
||||
\d+ rule_v1
|
||||
View "public.rule_v1"
|
||||
Column | Type | Modifiers | Storage | Description
|
||||
---------+---------+-----------+---------+-------------
|
||||
x | integer | | plain |
|
||||
column2 | integer | | plain |
|
||||
View definition:
|
||||
SELECT "*VALUES*".column1 AS x,
|
||||
"*VALUES*".column2
|
||||
FROM (VALUES (1,2)) "*VALUES*";
|
||||
|
||||
drop view rule_v1;
|
||||
create view rule_v1(x) as select * from (values(1,2)) v;
|
||||
\d+ rule_v1
|
||||
View "public.rule_v1"
|
||||
Column | Type | Modifiers | Storage | Description
|
||||
---------+---------+-----------+---------+-------------
|
||||
x | integer | | plain |
|
||||
column2 | integer | | plain |
|
||||
View definition:
|
||||
SELECT v.column1 AS x,
|
||||
v.column2
|
||||
FROM ( VALUES (1,2)) v;
|
||||
|
||||
drop view rule_v1;
|
||||
create view rule_v1(x) as select * from (values(1,2)) v(q,w);
|
||||
\d+ rule_v1
|
||||
View "public.rule_v1"
|
||||
Column | Type | Modifiers | Storage | Description
|
||||
--------+---------+-----------+---------+-------------
|
||||
x | integer | | plain |
|
||||
w | integer | | plain |
|
||||
View definition:
|
||||
SELECT v.q AS x,
|
||||
v.w
|
||||
FROM ( VALUES (1,2)) v(q, w);
|
||||
|
||||
drop view rule_v1;
|
||||
|
@ -953,6 +953,8 @@ select * from only t1;
|
||||
select * from only t1_1;
|
||||
select * from only t1_2;
|
||||
|
||||
reset constraint_exclusion;
|
||||
|
||||
-- test various flavors of pg_get_viewdef()
|
||||
|
||||
select pg_get_viewdef('shoe'::regclass) as unpretty;
|
||||
@ -1007,3 +1009,19 @@ ALTER RULE "_RETURN" ON rule_v1 RENAME TO abc; -- ON SELECT rule cannot be renam
|
||||
|
||||
DROP VIEW rule_v1;
|
||||
DROP TABLE rule_t1;
|
||||
|
||||
--
|
||||
-- check display of VALUES in view definitions
|
||||
--
|
||||
create view rule_v1 as values(1,2);
|
||||
\d+ rule_v1
|
||||
drop view rule_v1;
|
||||
create view rule_v1(x) as values(1,2);
|
||||
\d+ rule_v1
|
||||
drop view rule_v1;
|
||||
create view rule_v1(x) as select * from (values(1,2)) v;
|
||||
\d+ rule_v1
|
||||
drop view rule_v1;
|
||||
create view rule_v1(x) as select * from (values(1,2)) v(q,w);
|
||||
\d+ rule_v1
|
||||
drop view rule_v1;
|
||||
|
Reference in New Issue
Block a user