diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 2bc89bf84dc..443d4523789 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -3612,6 +3612,7 @@ ExecMergeNotMatched(ModifyTableContext *context, ResultRelInfo *resultRelInfo, MergeActionState *action = (MergeActionState *) lfirst(l); CmdType commandType = action->mas_action->commandType; TupleTableSlot *newslot; + char relkind; /* * Test condition, if any. @@ -3635,9 +3636,15 @@ ExecMergeNotMatched(ModifyTableContext *context, ResultRelInfo *resultRelInfo, */ newslot = ExecProject(action->mas_proj); mtstate->mt_merge_action = action; + relkind = mtstate->rootResultRelInfo->ri_RelationDesc->rd_rel->relkind; - rslot = ExecInsert(context, mtstate->rootResultRelInfo, + if (relkind == RELKIND_PARTITIONED_TABLE) + rslot = ExecInsert(context, mtstate->rootResultRelInfo, newslot, canSetTag, NULL, NULL); + else + rslot = ExecInsert(context, resultRelInfo, + newslot, canSetTag, NULL, NULL); + mtstate->mt_merge_inserted += 1; break; case CMD_NOTHING: