]> granicus.if.org Git - postgresql/commitdiff
Enforce child constraints during COPY TO a partitioned table.
authorRobert Haas <rhaas@postgresql.org>
Fri, 6 Apr 2018 15:42:28 +0000 (11:42 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 6 Apr 2018 15:42:28 +0000 (11:42 -0400)
The previous coding inadvertently checked the constraints for the
partitioned table rather than the target partition, which could
lead to data in a partition that fails to satisfy some constraint
on that partition.  This problem seems to date back to when
table partitioning was introduced; prior to that, there was only
one target table for a COPY, so the problem didn't occur, and the
code just didn't get updated.

Etsuro Fujita, reviewed by Amit Langote and Ashutosh Bapat

Discussion: https://postgr.es/message-id/5ABA4074.1090500%40lab.ntt.co.jp

src/backend/commands/copy.c

index a42861da0df7da4858b8047471602916944835a5..ae06609a1e1d948cd7bcff02c56a66424e1f2bd0 100644 (file)
@@ -2709,7 +2709,8 @@ CopyFrom(CopyState cstate)
                                        check_partition_constr = false;
 
                                /* Check the constraints of the tuple */
-                               if (cstate->rel->rd_att->constr || check_partition_constr)
+                               if (resultRelInfo->ri_RelationDesc->rd_att->constr ||
+                                       check_partition_constr)
                                        ExecConstraints(resultRelInfo, slot, estate, true);
 
                                if (useHeapMultiInsert)