summaryrefslogtreecommitdiff
path: root/src/backend/executor/execMain.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r--src/backend/executor/execMain.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index b8b9d2a85f7..ff12e2e1364 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1036,6 +1036,9 @@ InitPlan(QueryDesc *queryDesc, int eflags)
* Generally the parser and/or planner should have noticed any such mistake
* already, but let's make sure.
*
+ * For INSERT ON CONFLICT, the result relation is required to support the
+ * onConflictAction, regardless of whether a conflict actually occurs.
+ *
* For MERGE, mergeActions is the list of actions that may be performed. The
* result relation is required to support every action, regardless of whether
* or not they are all executed.
@@ -1045,7 +1048,7 @@ InitPlan(QueryDesc *queryDesc, int eflags)
*/
void
CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
- List *mergeActions)
+ OnConflictAction onConflictAction, List *mergeActions)
{
Relation resultRel = resultRelInfo->ri_RelationDesc;
FdwRoutine *fdwroutine;
@@ -1058,7 +1061,23 @@ CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
{
case RELKIND_RELATION:
case RELKIND_PARTITIONED_TABLE:
- CheckCmdReplicaIdentity(resultRel, operation);
+
+ /*
+ * For MERGE, check that the target relation supports each action.
+ * For other operations, just check the operation itself.
+ */
+ if (operation == CMD_MERGE)
+ foreach_node(MergeAction, action, mergeActions)
+ CheckCmdReplicaIdentity(resultRel, action->commandType);
+ else
+ CheckCmdReplicaIdentity(resultRel, operation);
+
+ /*
+ * For INSERT ON CONFLICT DO UPDATE, additionally check that the
+ * target relation supports UPDATE.
+ */
+ if (onConflictAction == ONCONFLICT_UPDATE)
+ CheckCmdReplicaIdentity(resultRel, CMD_UPDATE);
break;
case RELKIND_SEQUENCE:
ereport(ERROR,