aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/copy.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-01-04 14:36:34 -0500
committerRobert Haas <rhaas@postgresql.org>2017-01-04 14:36:34 -0500
commitf1b4c771ea74f42447dccaed42ffcdcccf3aa694 (patch)
treef1e7aa7a4b767602ff57b30dbcb459a7c86d1da5 /src/backend/commands/copy.c
parent3e353a7bc2dd6a9edfffe7e045c810b421f7ecc4 (diff)
downloadpostgresql-f1b4c771ea74f42447dccaed42ffcdcccf3aa694.tar.gz
postgresql-f1b4c771ea74f42447dccaed42ffcdcccf3aa694.zip
Fix reporting of constraint violations for table partitioning.
After a tuple is routed to a partition, it has been converted from the root table's row type to the partition's row type. ExecConstraints needs to report the failure using the original tuple and the parent's tuple descriptor rather than the ones for the selected partition. Amit Langote
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r--src/backend/commands/copy.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 071b97dee13..f56b2ac49b0 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2426,6 +2426,7 @@ CopyFrom(CopyState cstate)
cstate->rel,
1, /* dummy rangetable index */
true, /* do load partition check expression */
+ NULL,
0);
ExecOpenIndices(resultRelInfo, false);
@@ -2491,7 +2492,7 @@ CopyFrom(CopyState cstate)
for (;;)
{
TupleTableSlot *slot,
- *oldslot = NULL;
+ *oldslot;
bool skip_tuple;
Oid loaded_oid = InvalidOid;
@@ -2533,6 +2534,7 @@ CopyFrom(CopyState cstate)
ExecStoreTuple(tuple, slot, InvalidBuffer, false);
/* Determine the partition to heap_insert the tuple into */
+ oldslot = slot;
if (cstate->partition_dispatch_info)
{
int leaf_part_index;
@@ -2587,7 +2589,6 @@ CopyFrom(CopyState cstate)
* point on. Use a dedicated slot from this point on until
* we're finished dealing with the partition.
*/
- oldslot = slot;
slot = cstate->partition_tuple_slot;
Assert(slot != NULL);
ExecSetSlotDescriptor(slot, RelationGetDescr(partrel));
@@ -2624,7 +2625,7 @@ CopyFrom(CopyState cstate)
/* Check the constraints of the tuple */
if (cstate->rel->rd_att->constr ||
resultRelInfo->ri_PartitionCheck)
- ExecConstraints(resultRelInfo, slot, estate);
+ ExecConstraints(resultRelInfo, slot, oldslot, estate);
if (useHeapMultiInsert)
{
@@ -2686,10 +2687,6 @@ CopyFrom(CopyState cstate)
{
resultRelInfo = saved_resultRelInfo;
estate->es_result_relation_info = resultRelInfo;
-
- /* Switch back to the slot corresponding to the root table */
- Assert(oldslot != NULL);
- slot = oldslot;
}
}
}