From 6f3f3c1a2ef8872e16ec38a06c3b5c8f0b77e58f Mon Sep 17 00:00:00 2001 From: jian he Date: Sat, 24 Jan 2026 10:15:46 +0800 Subject: [PATCH v21 1/1] Add ON CONFLICT DO SELECT [FOR SHARE/UPDATE] misc fix Discussion: https://postgr.es/m/5fca222d-62ae-4a2f-9fcb-0eca56277094@Spark Discussion: https://postgr.es/m/2b5db2e6-8ece-44d0-9890-f256fdca9f7e@proxel.se Discussion: https://postgr.es/m/d631b406-13b7-433e-8c0b-c6040c4b4663@Spark --- doc/src/sgml/dml.sgml | 4 ++-- doc/src/sgml/ref/create_policy.sgml | 8 ++++---- src/backend/executor/nodeModifyTable.c | 11 +++++------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/doc/src/sgml/dml.sgml b/doc/src/sgml/dml.sgml index 988e19b347b..4d6938c7dde 100644 --- a/doc/src/sgml/dml.sgml +++ b/doc/src/sgml/dml.sgml @@ -388,8 +388,8 @@ UPDATE products SET price = price * 1.10 ON CONFLICT DO UPDATE clause, the old values will be non-NULL for conflicting rows. Similarly, in an INSERT with an - ON CONFLICT DO SELECT clause, you can look at the old - values to determine if your query inserted a row or not. + ON CONFLICT DO SELECT clause, you can look at the old + values to determine if your query inserted a row or not. If a DELETE is turned into an UPDATE by a rewrite rule, the new values may be non-NULL. diff --git a/doc/src/sgml/ref/create_policy.sgml b/doc/src/sgml/ref/create_policy.sgml index 50425a5e769..932c4b82736 100644 --- a/doc/src/sgml/ref/create_policy.sgml +++ b/doc/src/sgml/ref/create_policy.sgml @@ -293,10 +293,10 @@ CREATE POLICY name ON - If an INSERT has an ON CONFLICT - clause, SELECT permissions are required on the - relation, and the rows proposed for insertion are checked using - the relation's SELECT policies. + If an INSERT has an ON CONFLICT + clause, SELECT permissions are required on the + relation, and the rows proposed for insertion are checked using + the relation's SELECT policies. If a row proposed for insertion does not satisfy the relation's SELECT policies, an error is thrown (the INSERT is never silently diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 894dcb9467b..2f20ba71813 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -3017,12 +3017,11 @@ ExecOnConflictSelect(ModifyTableContext *context, if (lockStrength == LCS_NONE) { - /* Initialize "existing" - in the else branch, - this is done by ExecOnConflictLockRow */ - bool found = table_tuple_fetch_row_version(relation, conflictTid, - SnapshotAny, existing); - /* Even if the tuple is deleted, it must still be physically present */ - Assert(found); + if (!table_tuple_fetch_row_version(relation, + conflictTid, + SnapshotAny, + existing)) + elog(ERROR, "failed to fetch conflicting tuple for ON CONFLICT"); } else { -- 2.34.1