public inbox for [email protected]  
help / color / mirror / Atom feed
pgsql: Reject ADD CONSTRAINT NOT NULL if name mismatches existing const
2+ messages / 1 participants
[nested] [flat]

* pgsql: Reject ADD CONSTRAINT NOT NULL if name mismatches existing const
@ 2026-02-03 11:39  Álvaro Herrera <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Álvaro Herrera @ 2026-02-03 11:39 UTC (permalink / raw)
  To: [email protected]

Reject ADD CONSTRAINT NOT NULL if name mismatches existing constraint

When using ALTER TABLE ... ADD CONSTRAINT to add a not-null constraint
with an explicit name, we have to ensure that if the column is already
marked NOT NULL, the provided name matches the existing constraint name.
Failing to do so could lead to confusion regarding which constraint
object actually enforces the rule.

This patch adds a check to throw an error if the user tries to add a
named not-null constraint to a column that already has one with a
different name.

Reported-by: yanliang lei <[email protected]>
Co-authored-by: Álvaro Herrera <[email protected]>
Co-authored-bu: Srinath Reddy Sadipiralla <[email protected]>
Backpatch-through: 18
Discussion: https://postgr.es/m/19351-8f1c523ead498545%40postgresql.org

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/492a69e1407029f8c673484f44aa719a63323d77

Modified Files
--------------
src/backend/catalog/heap.c                |  1 +
src/backend/catalog/pg_constraint.c       | 21 +++++++++++++++++++--
src/include/catalog/pg_constraint.h       |  2 +-
src/test/regress/expected/constraints.out |  6 +++++-
src/test/regress/sql/constraints.sql      |  4 +++-
5 files changed, 29 insertions(+), 5 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Reject ADD CONSTRAINT NOT NULL if name mismatches existing const
@ 2026-02-03 11:39  Álvaro Herrera <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Álvaro Herrera @ 2026-02-03 11:39 UTC (permalink / raw)
  To: [email protected]

Reject ADD CONSTRAINT NOT NULL if name mismatches existing constraint

When using ALTER TABLE ... ADD CONSTRAINT to add a not-null constraint
with an explicit name, we have to ensure that if the column is already
marked NOT NULL, the provided name matches the existing constraint name.
Failing to do so could lead to confusion regarding which constraint
object actually enforces the rule.

This patch adds a check to throw an error if the user tries to add a
named not-null constraint to a column that already has one with a
different name.

Reported-by: yanliang lei <[email protected]>
Co-authored-by: Álvaro Herrera <[email protected]>
Co-authored-bu: Srinath Reddy Sadipiralla <[email protected]>
Backpatch-through: 18
Discussion: https://postgr.es/m/19351-8f1c523ead498545%40postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/96e2af605043974137d84edf5c0a24561956919e

Modified Files
--------------
src/backend/catalog/heap.c                |  1 +
src/backend/catalog/pg_constraint.c       | 21 +++++++++++++++++++--
src/include/catalog/pg_constraint.h       |  2 +-
src/test/regress/expected/constraints.out |  6 +++++-
src/test/regress/sql/constraints.sql      |  4 +++-
5 files changed, 29 insertions(+), 5 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-02-03 11:39 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-02-03 11:39 pgsql: Reject ADD CONSTRAINT NOT NULL if name mismatches existing const Álvaro Herrera <[email protected]>
2026-02-03 11:39 pgsql: Reject ADD CONSTRAINT NOT NULL if name mismatches existing const Álvaro Herrera <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox