]> granicus.if.org Git - postgresql/commit
Fix dumping of FUNCTION RTEs that contain non-function-call expressions.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 13 Jul 2017 23:24:44 +0000 (19:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 13 Jul 2017 23:25:03 +0000 (19:25 -0400)
commita3ca72ae9ac14acb2b1b9cd207ac0c8a01f1439a
tree3bf25fe8298b924295a93e75092e4c072b6efe3f
parent2036f71b751152e443beecfdd8bffbb4e17447c2
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
src/backend/utils/adt/ruleutils.c
src/test/regress/expected/create_table.out
src/test/regress/expected/create_view.out
src/test/regress/sql/create_view.sql