]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix detach of a partition that has a toplevel FK to a partitioned table
authorÁlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 21 Jan 2025 13:53:46 +0000 (14:53 +0100)
committerÁlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 21 Jan 2025 13:53:46 +0000 (14:53 +0100)
commitddab512ebb97c03d3c0dcfe0ea20d053a31e24d8
treeb7dac3e8371ead813a3cc7069bd2f981390f8ede
parentd62403c5129edc6444f5a17c7f15443d7500c5a3
Fix detach of a partition that has a toplevel FK to a partitioned table

In common cases, foreign keys are defined on the toplevel partitioned
table; but if instead one is defined on a partition and references a
partitioned table, and the referencing partition is detached, we would
examine the pg_constraint row on the partition being detached, and fail
to realize that the sub-constraints must be left alone.  This causes the
ALTER TABLE DETACH process to fail with

 ERROR:  could not find ON INSERT check triggers of foreign key constraint NNN

This is similar but not quite the same as what was fixed by
53af9491a043.  This bug doesn't affect branches earlier than 15, because
the detach procedure was different there, so we only backpatch down to
15.

Fix by skipping such modifying constraints that are children of other
constraints being detached.

Author: Amul Sul <sulamul@gmail.com>
Diagnosys-by: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAAJ_b97GuPh6wQPbxQS-Zpy16Oh+0aMv-w64QcGrLhCOZZ6p+g@mail.gmail.com
src/backend/commands/tablecmds.c
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql