In deparsing, parenthesize IS DOCUMENT where it is an operand.

isSimpleNode() and related code treated every XmlExpr as
self-delimiting.  Most of them are, because they look like function
calls with some extra decoration.  But "x IS DOCUMENT" is not: it is
a postfix test, like IS NULL.  Printed as the operand of another
operator, or as the operand of a postfix test, it was therefore not
parenthesized and could not be parsed back, or was parsed as something
unintended.  Under-parenthesization occurred even in non-pretty-print
cases, so that this could break dump/restore workflows.

To fix, treat IS DOCUMENT as neither simple nor function-like, and
give it the same treatment as other postfix tests.

Also pass the single argument of IS DOCUMENT, not the argument list,
to get_rule_expr_paren().  This avoids unnecessary parenthesization
of the argument.

Author: Henson Choi <[email protected]>
Reviewed-by: Prashant Chinnam <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: 
https://postgr.es/m/caaae_zdupskc8ihcctv67lxbqock+s4wqchho8xxz1t4tex...@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b08c4df3b733a77ae6404bee51ce0daa9d8a59cc

Modified Files
--------------
src/backend/utils/adt/ruleutils.c         | 33 ++++++++++++++++++++++++++-----
src/test/regress/expected/create_view.out | 21 +++++++++++++++++++-
src/test/regress/sql/create_view.sql      | 10 ++++++++++
3 files changed, 58 insertions(+), 6 deletions(-)

Reply via email to