diff options
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 3df5c5681f3..4d67176b64b 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -9356,6 +9356,8 @@ CloneForeignKeyConstraints(List **wqueue, Relation parentRel, * clone those constraints to the given partition. This is to be called * when the partition is being created or attached. * + * This ignores self-referencing FKs; those are handled by CloneFkReferencing. + * * This recurses to partitions, if the relation being attached is partitioned. * Recursion is done by calling addFkRecurseReferenced. */ @@ -9432,6 +9434,17 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel) } /* + * Don't clone self-referencing foreign keys, which can be in the + * partitioned table or in the partition-to-be. + */ + if (constrForm->conrelid == RelationGetRelid(parentRel) || + constrForm->conrelid == RelationGetRelid(partitionRel)) + { + ReleaseSysCache(tuple); + continue; + } + + /* * Because we're only expanding the key space at the referenced side, * we don't need to prevent any operation in the referencing table, so * AccessShareLock suffices (assumes that dropping the constraint |