Fix replica identity check for INSERT ON CONFLICT DO UPDATE.
authorDean Rasheed <[email protected]>
Thu, 4 Sep 2025 10:32:00 +0000 (11:32 +0100)
committerDean Rasheed <[email protected]>
Thu, 4 Sep 2025 10:32:00 +0000 (11:32 +0100)
commit344662848ac15efc89e09b7d39662d7c71b30e06
tree94fddb36b0e05fdeada83814d32d1fa2901662c0
parentc91c61b2417d0c36993deff03f09b1f64c821a1b
Fix replica identity check for INSERT ON CONFLICT DO UPDATE.

If an INSERT has an ON CONFLICT DO UPDATE clause, the executor must
check that the target relation supports UPDATE as well as INSERT. In
particular, it must check that the target relation has a REPLICA
IDENTITY if it publishes updates. Formerly, it was not doing this
check, which could lead to silently breaking replication.

Fix by adding such a check to CheckValidResultRel(), which requires
adding a new onConflictAction argument. In back-branches, preserve ABI
compatibility by introducing a wrapper function with the original
signature.

Author: Zhijie Hou <[email protected]>
Reviewed-by: Ashutosh Bapat <[email protected]>
Reviewed-by: Dean Rasheed <[email protected]>
Tested-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/OS3PR01MB57180C87E43A679A730482DF94B62@OS3PR01MB5718.jpnprd01.prod.outlook.com
Backpatch-through: 13
src/backend/commands/copyfrom.c
src/backend/executor/execMain.c
src/backend/executor/execPartition.c
src/backend/executor/nodeModifyTable.c
src/include/executor/executor.h
src/test/regress/expected/publication.out
src/test/regress/sql/publication.sql