diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-02-07 14:57:24 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-02-07 14:57:24 -0500 |
commit | 82406d6ff1aa9f2e77536d91492a2d2b7e20b5c7 (patch) | |
tree | 60081f6303d0f139ec26e885d2438c373f5901ca /src/backend/utils/adt | |
parent | bd0302c39d8439912c0643058913236e69128830 (diff) | |
download | postgresql-82406d6ff1aa9f2e77536d91492a2d2b7e20b5c7.tar.gz postgresql-82406d6ff1aa9f2e77536d91492a2d2b7e20b5c7.zip |
Fix deparsing of ON CONFLICT arbiter WHERE clauses.
The parser doesn't allow qualification of column names appearing in
these clauses, but ruleutils.c would sometimes qualify them, leading
to dump/reload failures. Per bug #13891 from Onder Kalaci.
(In passing, make stanzas in ruleutils.c that save/restore varprefix
more consistent.)
Peter Geoghegan
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 3783e977dd8..690df14af22 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -5526,9 +5526,21 @@ get_insert_query_def(Query *query, deparse_context *context) /* Add a WHERE clause (for partial indexes) if given */ if (confl->arbiterWhere != NULL) { + bool save_varprefix; + + /* + * Force non-prefixing of Vars, since parser assumes that they + * belong to target relation. WHERE clause does not use + * InferenceElem, so this is separately required. + */ + save_varprefix = context->varprefix; + context->varprefix = false; + appendContextKeyword(context, " WHERE ", -PRETTYINDENT_STD, PRETTYINDENT_STD, 1); get_rule_expr(confl->arbiterWhere, context, false); + + context->varprefix = save_varprefix; } } else if (confl->constraint != InvalidOid) @@ -7950,13 +7962,14 @@ get_rule_expr(Node *node, deparse_context *context, case T_InferenceElem: { InferenceElem *iexpr = (InferenceElem *) node; - bool varprefix = context->varprefix; + bool save_varprefix; bool need_parens; /* * InferenceElem can only refer to target relation, so a - * prefix is never useful. + * prefix is not useful, and indeed would cause parse errors. */ + save_varprefix = context->varprefix; context->varprefix = false; /* @@ -7976,7 +7989,7 @@ get_rule_expr(Node *node, deparse_context *context, if (need_parens) appendStringInfoChar(buf, ')'); - context->varprefix = varprefix; + context->varprefix = save_varprefix; if (iexpr->infercollid) appendStringInfo(buf, " COLLATE %s", |