diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-07-13 19:24:44 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-07-13 19:24:44 -0400 |
commit | 3b0c2dbed07e52b73a87d94ed128784eb5c25de7 (patch) | |
tree | 6e3144f3f5db31a05fa8dfe2f940a16c86cd6f18 /src/test | |
parent | cb02cbc9d7dbf061e9a4862584481513253a0db5 (diff) | |
download | postgresql-3b0c2dbed07e52b73a87d94ed128784eb5c25de7.tar.gz postgresql-3b0c2dbed07e52b73a87d94ed128784eb5c25de7.zip |
Fix dumping of FUNCTION RTEs that contain non-function-call expressions.
The grammar will only accept something syntactically similar to a function
call in a function-in-FROM expression. However, there are various ways
to input something that ruleutils.c won't deparse that way, potentially
leading to a view or rule that fails dump/reload. Fix by inserting a
dummy CAST around anything that isn't going to deparse as a function
(which is one of the ways to get something like that in there in the
first place).
In HEAD, also make use of the infrastructure added by this to avoid
emitting unnecessary parentheses in CREATE INDEX deparsing. I did
not change that in back branches, thinking that people might find it
to be unexpected/unnecessary behavioral change.
In HEAD, also fix incorrect logic for when to add extra parens to
partition key expressions. Somebody apparently thought they could
get away with simpler logic than pg_get_indexdef_worker has, but
they were wrong --- a counterexample is PARTITION BY LIST ((a[1])).
Ignoring the prettyprint flag for partition expressions isn't exactly
a nice solution anyway.
This has been broken all along, so back-patch to all supported branches.
Discussion: https://postgr.es/m/10477.1499970459@sss.pgh.pa.us
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/create_view.out | 23 | ||||
-rw-r--r-- | src/test/regress/sql/create_view.sql | 11 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/test/regress/expected/create_view.out b/src/test/regress/expected/create_view.out index b1c3cff9315..049fe0d778c 100644 --- a/src/test/regress/expected/create_view.out +++ b/src/test/regress/expected/create_view.out @@ -1567,6 +1567,29 @@ select pg_get_viewdef('tt19v', true); 'foo'::text = ANY ((( SELECT ARRAY['abc'::text, 'def'::text, 'foo'::text] AS "array"))::text[]) AS c2; (1 row) +-- check display of assorted RTE_FUNCTION expressions +create view tt20v as +select * from + coalesce(1,2) as c, + collation for ('x'::text) col, + current_date as d, + cast(1+2 as int4) as i4, + cast(1+2 as int8) as i8; +select pg_get_viewdef('tt20v', true); + pg_get_viewdef +--------------------------------------------- + SELECT c.c, + + col.col, + + d.d, + + i4.i4, + + i8.i8 + + FROM COALESCE(1, 2) c(c), + + pg_collation_for('x'::text) col(col), + + CAST('now'::text::date AS date) d(d), + + CAST(1 + 2 AS integer) i4(i4), + + CAST((1 + 2)::bigint AS bigint) i8(i8); +(1 row) + -- clean up all the random objects we made above set client_min_messages = warning; DROP SCHEMA temp_view_test CASCADE; diff --git a/src/test/regress/sql/create_view.sql b/src/test/regress/sql/create_view.sql index 5fe8b94aae0..d7b461f8d4b 100644 --- a/src/test/regress/sql/create_view.sql +++ b/src/test/regress/sql/create_view.sql @@ -520,6 +520,17 @@ select 'foo'::text = any(array['abc','def','foo']::text[]) c1, 'foo'::text = any((select array['abc','def','foo']::text[])::text[]) c2; select pg_get_viewdef('tt19v', true); +-- check display of assorted RTE_FUNCTION expressions + +create view tt20v as +select * from + coalesce(1,2) as c, + collation for ('x'::text) col, + current_date as d, + cast(1+2 as int4) as i4, + cast(1+2 as int8) as i8; +select pg_get_viewdef('tt20v', true); + -- clean up all the random objects we made above set client_min_messages = warning; DROP SCHEMA temp_view_test CASCADE; |