Choose FK name correctly during partition attachment
authorAlvaro Herrera <[email protected]>
Thu, 8 Sep 2022 11:17:02 +0000 (13:17 +0200)
committerAlvaro Herrera <[email protected]>
Thu, 8 Sep 2022 11:17:02 +0000 (13:17 +0200)
commitade2409b18e9c5d68afb13831da69198d06e5062
treed3f0f8c665bb7a41f60017e0c7fe25540bbb153f
parentdd38ff28addc13594c0f9e2a62ef2ffa59230598
Choose FK name correctly during partition attachment

During ALTER TABLE ATTACH PARTITION, if the name of a parent's foreign
key constraint is already used on the partition, the code tries to
choose another one before the FK attributes list has been populated,
so the resulting constraint name was "<relname>__fkey" instead of
"<relname>_<attrs>_fkey".  Repair, and add a test case.

Backpatch to 12.  In 11, the code to attach a partition was not smart
enough to cope with conflicting constraint names, so the problem doesn't
exist there.

Author: Jehan-Guillaume de Rorthais <[email protected]>
Discussion: https://postgr.es/m/20220901184156.738ebee5@karst
src/backend/commands/tablecmds.c
src/test/regress/expected/constraints.out
src/test/regress/sql/constraints.sql