Rely on executor utils to build targetlist for DML RETURNING.
authorAndres Freund <andres@anarazel.de>
Wed, 16 Aug 2017 08:03:51 +0000 (01:03 -0700)
committerAndres Freund <andres@anarazel.de>
Fri, 1 Sep 2017 06:22:35 +0000 (23:22 -0700)
src/backend/executor/nodeModifyTable.c

index e12721a9b6ae56a0615062a371cd00ef29d280bd..57946e1591dd5d5278535fa2c6e827c6fef24e3a 100644 (file)
@@ -1793,7 +1793,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
    int         nplans = list_length(node->plans);
    ResultRelInfo *saved_resultRelInfo;
    ResultRelInfo *resultRelInfo;
-   TupleDesc   tupDesc;
    Plan       *subplan;
    ListCell   *l;
    int         i;
@@ -2027,12 +2026,11 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
         * Initialize result tuple slot and assign its rowtype using the first
         * RETURNING list.  We assume the rest will look the same.
         */
-       tupDesc = ExecTypeFromTL((List *) linitial(node->returningLists),
-                                false);
+       mtstate->ps.plan->targetlist = (List *) linitial(node->returningLists);
 
        /* Set up a slot for the output of the RETURNING projection(s) */
        ExecInitResultTupleSlot(estate, &mtstate->ps);
-       ExecAssignResultType(&mtstate->ps, tupDesc);
+       ExecAssignResultTypeFromTL(&mtstate->ps);
        slot = mtstate->ps.ps_ResultTupleSlot;
 
        /* Need an econtext too */
@@ -2084,9 +2082,9 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
         * We still must construct a dummy result tuple type, because InitPlan
         * expects one (maybe should change that?).
         */
-       tupDesc = ExecTypeFromTL(NIL, false);
+       mtstate->ps.plan->targetlist = NIL;
        ExecInitResultTupleSlot(estate, &mtstate->ps);
-       ExecAssignResultType(&mtstate->ps, tupDesc);
+       ExecAssignResultTypeFromTL(&mtstate->ps);
 
        mtstate->ps.ps_ExprContext = NULL;
    }