]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Add support for altering CHECK constraint enforceability
authorAndrew Dunstan <andrew@dunslane.net>
Wed, 11 Mar 2026 20:15:35 +0000 (16:15 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Wed, 11 Mar 2026 20:15:35 +0000 (16:15 -0400)
commit342051d73b386ad763e13930e15031f7ba5367f5
tree73e412aefc522f27a6ee1ffccd6521d063288f50
parenta9747153e14d38a72d2468744fab946643423924
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.universality@gmail.com>
Reviewed-by: Robert Treat <rob@xzilla.net>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Amul Sul <sulamul@gmail.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@cybertec.at>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CACJufxHCh_FU-FsEwsCvg9mN6-5tzR6H9ntn+0KUgTCaerDOmg@mail.gmail.com
doc/src/sgml/ref/alter_table.sgml
src/backend/commands/tablecmds.c
src/test/regress/expected/constraints.out
src/test/regress/expected/inherit.out
src/test/regress/sql/constraints.sql
src/test/regress/sql/inherit.sql