Avoid name collision with NOT NULL constraints
Álvaro Herrera <alvherre@kurilemu.de>
Avoid name collision with NOT NULL constraints If a CREATE TABLE statement defined a constraint whose name is identical to the name generated for a NOT NULL constraint, we'd throw an (unnecessary) unique key violation error on pg_constraint_conrelid_contypid_conname_index: this can easily be avoided by choosing a different name for the NOT NULL constraint. Fix by passing the constraint names already created by AddRelationNewConstraints() to AddRelationNotNullConstraints(), so that the latter can avoid name collisions with them. Bug: #19393 Author: Laurenz Albe <laurenz.albe@cybertec.at> Reported-by: Hüseyin Demir <huseyin.d3r@gmail.com> Backpatch-through: 18 Discussion: https://postgr.es/m/19393-6a82427485a744cf@postgresql.org
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/catalog/heap.c | modified | +5 −3 |
| src/backend/commands/tablecmds.c | modified | +14 −4 |
| src/include/catalog/heap.h | modified | +2 −1 |
| src/test/regress/expected/create_table.out | modified | +6 −0 |
| src/test/regress/sql/create_table.sql | modified | +7 −0 |
Discussion
- BUG #19393: pg_upgrade fails with duplicate key violation when CHECK constraint named *_not_null exists 17 messages · 2026-02-04 → 2026-02-23