Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc2ca93

Browse files
committed
Fix deparsing of ON CONFLICT arbiter WHERE clauses.
The parser doesn't allow qualification of column names appearing inthese clauses, but ruleutils.c would sometimes qualify them, leadingto dump/reload failures. Per bug #13891 from Onder Kalaci.(In passing, make stanzas in ruleutils.c that save/restore varprefixmore consistent.)Peter Geoghegan
1 parent1d76c97 commitcc2ca93

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5532,9 +5532,21 @@ get_insert_query_def(Query *query, deparse_context *context)
55325532
/* Add a WHERE clause (for partial indexes) if given */
55335533
if (confl->arbiterWhere!=NULL)
55345534
{
5535+
boolsave_varprefix;
5536+
5537+
/*
5538+
* Force non-prefixing of Vars, since parser assumes that they
5539+
* belong to target relation. WHERE clause does not use
5540+
* InferenceElem, so this is separately required.
5541+
*/
5542+
save_varprefix=context->varprefix;
5543+
context->varprefix= false;
5544+
55355545
appendContextKeyword(context," WHERE ",
55365546
-PRETTYINDENT_STD,PRETTYINDENT_STD,1);
55375547
get_rule_expr(confl->arbiterWhere,context, false);
5548+
5549+
context->varprefix=save_varprefix;
55385550
}
55395551
}
55405552
elseif (confl->constraint!=InvalidOid)
@@ -7956,13 +7968,14 @@ get_rule_expr(Node *node, deparse_context *context,
79567968
caseT_InferenceElem:
79577969
{
79587970
InferenceElem*iexpr= (InferenceElem*)node;
7959-
boolvarprefix=context->varprefix;
7971+
boolsave_varprefix;
79607972
boolneed_parens;
79617973

79627974
/*
79637975
* InferenceElem can only refer to target relation, so a
7964-
* prefix isnever useful.
7976+
* prefix isnot useful, and indeed would cause parse errors.
79657977
*/
7978+
save_varprefix=context->varprefix;
79667979
context->varprefix= false;
79677980

79687981
/*
@@ -7982,7 +7995,7 @@ get_rule_expr(Node *node, deparse_context *context,
79827995
if (need_parens)
79837996
appendStringInfoChar(buf,')');
79847997

7985-
context->varprefix=varprefix;
7998+
context->varprefix=save_varprefix;
79867999

79878000
if (iexpr->infercollid)
79888001
appendStringInfo(buf," COLLATE %s",

‎src/test/regress/expected/rules.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ SELECT definition FROM pg_rules WHERE tablename = 'hats' ORDER BY rulename;
28462846
CREATE RULE hat_nosert AS +
28472847
ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) +
28482848
VALUES (new.hat_name, new.hat_color) ON CONFLICT(hat_name COLLATE "C" bpchar_pattern_ops)+
2849-
WHERE (hat_data.hat_color = 'green'::bpchar) DO NOTHING +
2849+
WHERE (hat_color = 'green'::bpchar) DO NOTHING +
28502850
RETURNING hat_data.hat_name, +
28512851
hat_data.hat_color;
28522852
(1 row)
@@ -2871,7 +2871,7 @@ SELECT tablename, rulename, definition FROM pg_rules
28712871
hats | hat_nosert | CREATE RULE hat_nosert AS +
28722872
| | ON INSERT TO hats DO INSTEAD INSERT INTO hat_data (hat_name, hat_color) +
28732873
| | VALUES (new.hat_name, new.hat_color) ON CONFLICT(hat_name COLLATE "C" bpchar_pattern_ops)+
2874-
| | WHERE (hat_data.hat_color = 'green'::bpchar) DO NOTHING +
2874+
| | WHERE (hat_color = 'green'::bpchar) DO NOTHING +
28752875
| | RETURNING hat_data.hat_name, +
28762876
| | hat_data.hat_color;
28772877
(1 row)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp