pgsql: Add support for altering CHECK constraint enforceability

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add support for altering CHECK constraint enforceability
Date: 2026-03-11 20:16:34
Message-ID: E1w0Pys-003W3S-32@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add support for altering CHECK constraint enforceability

This commit adds support for ALTER TABLE ALTER CONSTRAINT ... [NOT]
ENFORCED for CHECK constraints. Previously, only foreign key
constraints could have their enforceability altered.

When changing from NOT ENFORCED to ENFORCED, the operation not only
updates catalog information but also performs a full table scan in
Phase 3 to validate that existing data satisfies the constraint.

For partitioned tables and inheritance hierarchies, the operation
recurses to all child tables. When changing to NOT ENFORCED, we must
recurse even if the parent is already NOT ENFORCED, since child
constraints may still be ENFORCED.

Author: Jian He <jian(dot)universality(at)gmail(dot)com>
Reviewed-by: Robert Treat <rob(at)xzilla(dot)net>
Reviewed-by: Kirill Reshke <reshkekirill(at)gmail(dot)com>
Reviewed-by: Amul Sul <sulamul(at)gmail(dot)com>
Reviewed-by: Zsolt Parragi <zsolt(dot)parragi(at)cybertec(dot)at>
Reviewed-by: Andrew Dunstan <andrew(at)dunslane(dot)net>
Discussion: https://postgr.es/m/CACJufxHCh_FU-FsEwsCvg9mN6-5tzR6H9ntn+0KUgTCaerDOmg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/342051d73b386ad763e13930e15031f7ba5367f5

Modified Files
--------------
doc/src/sgml/ref/alter_table.sgml | 4 +-
src/backend/commands/tablecmds.c | 194 ++++++++++++++++++++++++++++--
src/test/regress/expected/constraints.out | 80 ++++++++++++
src/test/regress/expected/inherit.out | 62 ++++++++++
src/test/regress/sql/constraints.sql | 52 ++++++++
src/test/regress/sql/inherit.sql | 43 +++++++
6 files changed, 423 insertions(+), 12 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2026-03-11 21:30:48 pgsql: Fix use of volatile.
Previous Message Andres Freund 2026-03-11 19:02:57 pgsql: bufmgr: Remove the, now obsolete, BM_JUST_DIRTIED