Skip to content

Instantly share code, notes, and snippets.

@Gurpartap
Created December 14, 2015 14:35
Show Gist options
  • Save Gurpartap/b213202380f655bd10a1 to your computer and use it in GitHub Desktop.
Save Gurpartap/b213202380f655bd10a1 to your computer and use it in GitHub Desktop.
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index dabaea9..9db4c91 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -1181,8 +1181,17 @@ ExecOnConflictUpdate(ModifyTableState *mtstate,
/* Project the new tuple version */
ExecProject(resultRelInfo->ri_onConflictSetProj, NULL);
+ /*
+ * Note that it is possible that the target tuple has been modified in
+ * this session, after the above heap_lock_tuple. We choose to not error
+ * out in that case, in line with ExecUpdate's treatment of similar
+ * cases. This can happen if an UPDATE is triggered from within
+ * ExecQual(), ExecWithCheckOptions() or ExecProject() above, e.g. by
+ * selecting from a wCTE in the ON CONFLICT's SET.
+ */
+
/* Execute UPDATE with projection */
- *returning = ExecUpdate(&tuple.t_data->t_ctid, NULL,
+ *returning = ExecUpdate(&tuple.t_self, NULL,
mtstate->mt_conflproj, planSlot,
&mtstate->mt_epqstate, mtstate->ps.state,
canSetTag);
@Gurpartap
Copy link
Author

brew edit postgresql
  devel do
    url "https://ftp.postgresql.org/pub/source/v9.5beta2/postgresql-9.5beta2.tar.bz2"
    sha256 "031051cd50ebc4ab07da4e6587c59af6712b21979c486b1af0c31e97e1d9e703"
    version "9.5beta2"
++    patch do
++        url "https://gist.githubusercontent.com/Gurpartap/b213202380f655bd10a1/raw/8901e21b50bfae67c2c026a1060b2d2e28867108/postgresql9.6beta2-on-conflict-update-trigger.diff"
++        sha256 "445093dcb8a36c10d41b7836d4a1190ba8f45020b420bf17fc9f327ec477d82b"
++    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment