aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/copy.c
diff options
context:
space:
mode:
authorAndrew Gierth <rhodiumtoad@postgresql.org>2017-06-28 18:59:01 +0100
committerAndrew Gierth <rhodiumtoad@postgresql.org>2017-06-28 18:59:01 +0100
commitc46c0e5202e8cfe750c6629db7852fdb15d528f3 (patch)
tree710f0377e15e9ddad018d53fbd09aade535136d6 /src/backend/commands/copy.c
parent501ed02cf6f4f60c3357775eb07578aebc912d3a (diff)
downloadpostgresql-c46c0e5202e8cfe750c6629db7852fdb15d528f3.tar.gz
postgresql-c46c0e5202e8cfe750c6629db7852fdb15d528f3.zip
Fix transition tables for wCTEs.
The original coding didn't handle this case properly; each separate DML substatement needs its own set of transitions. Patch by Thomas Munro Discussion: https://postgr.es/m/CAL9smLCDQ%3D2o024rBgtD4WihzX8B3C6u_oSQ2K3%2BR5grJrV0bg%40mail.gmail.com
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r--src/backend/commands/copy.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index a4c02e6b7c5..f391828e74f 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1416,6 +1416,12 @@ BeginCopy(ParseState *pstate,
errmsg("table \"%s\" does not have OIDs",
RelationGetRelationName(cstate->rel))));
+ /*
+ * If there are any triggers with transition tables on the named
+ * relation, we need to be prepared to capture transition tuples.
+ */
+ cstate->transition_capture = MakeTransitionCaptureState(rel->trigdesc);
+
/* Initialize state for CopyFrom tuple routing. */
if (is_from && rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
{
@@ -1440,14 +1446,6 @@ BeginCopy(ParseState *pstate,
cstate->partition_tuple_slot = partition_tuple_slot;
/*
- * If there are any triggers with transition tables on the named
- * relation, we need to be prepared to capture transition tuples
- * from child relations too.
- */
- cstate->transition_capture =
- MakeTransitionCaptureState(rel->trigdesc);
-
- /*
* If we are capturing transition tuples, they may need to be
* converted from partition format back to partitioned table
* format (this is only ever necessary if a BEFORE trigger
@@ -2807,7 +2805,7 @@ CopyFrom(CopyState cstate)
pq_endmsgread();
/* Execute AFTER STATEMENT insertion triggers */
- ExecASInsertTriggers(estate, resultRelInfo);
+ ExecASInsertTriggers(estate, resultRelInfo, cstate->transition_capture);
/* Handle queued AFTER triggers */
AfterTriggerEndQuery(estate);
@@ -2935,7 +2933,7 @@ CopyFromInsertBatch(CopyState cstate, EState *estate, CommandId mycid,
cstate->cur_lineno = firstBufferedLineNo + i;
ExecARInsertTriggers(estate, resultRelInfo,
bufferedTuples[i],
- NIL, NULL);
+ NIL, cstate->transition_capture);
}
}