From c46c0e5202e8cfe750c6629db7852fdb15d528f3 Mon Sep 17 00:00:00 2001 From: Andrew Gierth Date: Wed, 28 Jun 2017 18:59:01 +0100 Subject: 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 --- src/backend/commands/copy.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/backend/commands/copy.c') 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) { @@ -1439,14 +1445,6 @@ BeginCopy(ParseState *pstate, cstate->partition_tupconv_maps = partition_tupconv_maps; 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 @@ -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); } } -- cgit v1.2.3