pgsql: Avoid name collision with NOT NULL constraints

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid name collision with NOT NULL constraints
Date: 2026-02-21 11:25:23
Message-ID: E1vtl6x-000SOU-2K@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)albe(at)cybertec(dot)at>
Reported-by: Hüseyin Demir <huseyin(dot)d3r(at)gmail(dot)com>
Backpatch-through: 18
Discussion: https://postgr.es/m/19393-6a82427485a744cf@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0eeffd31bf9bb73446387cd7eebbbf43148aa281

Modified Files
--------------
src/backend/catalog/heap.c | 8 +++++---
src/backend/commands/tablecmds.c | 18 ++++++++++++++----
src/include/catalog/heap.h | 3 ++-
src/test/regress/expected/create_table.out | 6 ++++++
src/test/regress/sql/create_table.sql | 7 +++++++
5 files changed, 34 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2026-02-21 12:09:53 pgsql: Update .abi-compliance-history for AddRelationNotNullConstraints
Previous Message Bertrand Drouvot 2026-02-21 09:42:13 Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)