From 23cccb17fe0bbb5df86780da5c346cc060c21421 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Fri, 28 Jun 2019 14:51:08 -0400 Subject: Fix for dropped columns in a partitioned table's default partition We forgot to map column numbers to/from the default partition for various operations, leading to valid cases failing with spurious errors, such as ERROR: attribute N of type some_partition has been dropped It was also possible that the search for conflicting rows in the default partition when attaching another partition would fail to detect some. Secondarily, it was also possible that such a search should be skipped (because the constraint was implied) but wasn't. Fix all this by mapping column numbers when necessary. Reported by: Daniel Wilches Author: Amit Langote Discussion: https://postgr.es/m/15873-8c61945d6b3ef87c@postgresql.org --- src/backend/commands/tablecmds.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/backend/commands/tablecmds.c') diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7dcd634a1ae..fd67d2a8413 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -15682,6 +15682,13 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) defaultrel = table_open(defaultPartOid, NoLock); defPartConstraint = get_proposed_default_constraint(partBoundConstraint); + /* + * Map the Vars in the constraint expression from rel's attnos to + * defaultrel's. + */ + defPartConstraint = + map_partition_varattnos(defPartConstraint, + 1, defaultrel, rel, NULL); QueuePartitionConstraintValidation(wqueue, defaultrel, defPartConstraint, true); -- cgit v1.2.3