diff --git a/doc/src/sgml/ref/insert.sgml b/doc/src/sgml/ref/insert.sgml
index 8da82e474abde..c74e16bd8cce0 100644
--- a/doc/src/sgml/ref/insert.sgml
+++ b/doc/src/sgml/ref/insert.sgml
@@ -24,7 +24,7 @@ PostgreSQL documentation
[ WITH [ RECURSIVE ] with_query [, ...] ]
INSERT INTO table_name [ ( column_name [, ...] ) ]
{ DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
- [ ON CONFLICT [ ( { column_name_index | ( expression_index ) } [ COLLATE collation ] [ opclass ] [, ...] ) [ WHERE index_predicate ] ]
+ [ ON CONFLICT [ ( { column_name_index | ( expression_index ) } [ COLLATE collation ] [ opclass ] [, ...] [ WHERE index_predicate ] ) ]
{ IGNORE | UPDATE
SET { column_name = { expression | DEFAULT } |
( column_name [, ...] ) = ( { expression | DEFAULT } [, ...] )
@@ -681,7 +681,7 @@ INSERT INTO employees_log SELECT *, current_timestamp FROM upd;
-- just use a regular unique constraint on did if that was
-- all that was available.
INSERT INTO distributors (did, dname) VALUES (9, 'Antwerp Design')
- ON CONFLICT (did) WHERE is_active IGNORE;
+ ON CONFLICT (did WHERE is_active) IGNORE;
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 792a89cd17779..5f15690808fd1 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -662,8 +662,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
%nonassoc IS ISNULL NOTNULL /* IS sets precedence for IS NULL, etc */
%nonassoc '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
%nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
-%nonassoc UPDATE
-%nonassoc IGNORE_P
%nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
%nonassoc OVERLAPS
%left POSTFIXOP /* dummy for postfix Op rules */
@@ -9436,11 +9434,11 @@ opt_on_conflict:
;
opt_conf_expr:
- '(' index_params ')' where_clause
+ '(' index_params where_clause ')'
{
$$ = makeNode(InferClause);
$$->indexElems = $2;
- $$->whereClause = $4;
+ $$->whereClause = $3;
$$->location = @1;
}
| /*EMPTY*/
diff --git a/src/test/regress/expected/insert_conflict.out b/src/test/regress/expected/insert_conflict.out
index c0db692a9aa4a..16ccc7fdb7620 100644
--- a/src/test/regress/expected/insert_conflict.out
+++ b/src/test/regress/expected/insert_conflict.out
@@ -311,16 +311,16 @@ drop index fruit_index;
--
create unique index partial_key_index on insertconflicttest(key) where fruit like '%berry';
-- Succeeds
-insert into insertconflicttest values (23, 'Blackberry') on conflict (key) where fruit like '%berry' update set fruit = excluded.fruit;
-insert into insertconflicttest values (23, 'Blackberry') on conflict (key) where fruit like '%berry' and fruit = 'inconsequential' ignore;
+insert into insertconflicttest values (23, 'Blackberry') on conflict (key where fruit like '%berry') update set fruit = excluded.fruit;
+insert into insertconflicttest values (23, 'Blackberry') on conflict (key where fruit like '%berry' and fruit = 'inconsequential') ignore;
-- fails
insert into insertconflicttest values (23, 'Blackberry') on conflict (key) update set fruit = excluded.fruit;
ERROR: could not infer which unique index to use from expressions/columns and predicate provided for ON CONFLICT
-insert into insertconflicttest values (23, 'Blackberry') on conflict (key) where fruit like '%berry' or fruit = 'consequential' ignore;
+insert into insertconflicttest values (23, 'Blackberry') on conflict (key where fruit like '%berry' or fruit = 'consequential') ignore;
ERROR: could not infer which unique index to use from expressions/columns and predicate provided for ON CONFLICT
-insert into insertconflicttest values (23, 'Blackberry') on conflict (fruit) where fruit like '%berry' update set fruit = excluded.fruit;
+insert into insertconflicttest values (23, 'Blackberry') on conflict (fruit where fruit like '%berry') update set fruit = excluded.fruit;
ERROR: could not infer which unique index to use from expressions/columns and predicate provided for ON CONFLICT
-insert into insertconflicttest values (23, 'Uncovered by Index') on conflict (key) where fruit like '%berry' ignore;
+insert into insertconflicttest values (23, 'Uncovered by Index') on conflict (key where fruit like '%berry') ignore;
ERROR: inferred arbiter partial unique index's predicate does not cover tuple proposed for insertion
DETAIL: ON CONFLICT inference clause implies that the tuple proposed for insertion must be covered by the predicate of partial index "partial_key_index".
drop index partial_key_index;
diff --git a/src/test/regress/sql/insert_conflict.sql b/src/test/regress/sql/insert_conflict.sql
index 249adde1cef64..d3a9151939545 100644
--- a/src/test/regress/sql/insert_conflict.sql
+++ b/src/test/regress/sql/insert_conflict.sql
@@ -186,14 +186,14 @@ drop index fruit_index;
create unique index partial_key_index on insertconflicttest(key) where fruit like '%berry';
-- Succeeds
-insert into insertconflicttest values (23, 'Blackberry') on conflict (key) where fruit like '%berry' update set fruit = excluded.fruit;
-insert into insertconflicttest values (23, 'Blackberry') on conflict (key) where fruit like '%berry' and fruit = 'inconsequential' ignore;
+insert into insertconflicttest values (23, 'Blackberry') on conflict (key where fruit like '%berry') update set fruit = excluded.fruit;
+insert into insertconflicttest values (23, 'Blackberry') on conflict (key where fruit like '%berry' and fruit = 'inconsequential') ignore;
-- fails
insert into insertconflicttest values (23, 'Blackberry') on conflict (key) update set fruit = excluded.fruit;
-insert into insertconflicttest values (23, 'Blackberry') on conflict (key) where fruit like '%berry' or fruit = 'consequential' ignore;
-insert into insertconflicttest values (23, 'Blackberry') on conflict (fruit) where fruit like '%berry' update set fruit = excluded.fruit;
-insert into insertconflicttest values (23, 'Uncovered by Index') on conflict (key) where fruit like '%berry' ignore;
+insert into insertconflicttest values (23, 'Blackberry') on conflict (key where fruit like '%berry' or fruit = 'consequential') ignore;
+insert into insertconflicttest values (23, 'Blackberry') on conflict (fruit where fruit like '%berry') update set fruit = excluded.fruit;
+insert into insertconflicttest values (23, 'Uncovered by Index') on conflict (key where fruit like '%berry') ignore;
drop index partial_key_index;