/* 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)
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;
/*
if (need_parens)
appendStringInfoChar(buf, ')');
- context->varprefix = varprefix;
+ context->varprefix = save_varprefix;
if (iexpr->infercollid)
appendStringInfo(buf, " COLLATE %s",
CREATE RULE hat_nosert AS +
ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) +
VALUES (new.hat_name, new.hat_color) ON CONFLICT(hat_name COLLATE "C" bpchar_pattern_ops)+
- WHERE (hat_data.hat_color = 'green'::bpchar) DO NOTHING +
+ WHERE (hat_color = 'green'::bpchar) DO NOTHING +
RETURNING hat_data.hat_name, +
hat_data.hat_color;
(1 row)
hats | hat_nosert | CREATE RULE hat_nosert AS +
| | ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) +
| | VALUES (new.hat_name, new.hat_color) ON CONFLICT(hat_name COLLATE "C" bpchar_pattern_ops)+
- | | WHERE (hat_data.hat_color = 'green'::bpchar) DO NOTHING +
+ | | WHERE (hat_color = 'green'::bpchar) DO NOTHING +
| | RETURNING hat_data.hat_name, +
| | hat_data.hat_color;
(1 row)