Re: NOT NULL NOT ENFORCED - Mailing list pgsql-hackers

From jian he
Subject Re: NOT NULL NOT ENFORCED
Date
Msg-id CACJufxECCgByCscWPCKCmHtW1f9Riz7S72sQ0HzDht3VQEoWfw@mail.gmail.com
Whole thread
In response to NOT NULL NOT ENFORCED  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
On Fri, Sep 11, 2026 at 2:47 PM Sebas Mannem <sebas@mannem.nl> wrote:
>
> Hi,
> this commit message could be much clearer on what the patch does.

I refactored some comments and rebased it.
Please check the attached v6.
Below is the full commit message:
NOT NULL NOT ENFORCED

This completes SQL feature F492 (Optional table constraint enforcement), which
previously carried the remark "except not-null constraints" in sql_features.txt.

A NOT ENFORCED not-null constraint is stored in pg_constraint with both
conenforced and convalidated fields set to false, and pg_attribute.attnotnull is
left false as well.  Nulls are accepted and existing rows are not verified.

Rules for NOT-NULL constraint:
* A column has at most one not-null constraint, enforced or not.  Adding
  one with a different enforcement status is not allowed.
* ALTER COLUMN SET NOT NULL and VALIDATE CONSTRAINT cannot be applied to a NOT
  ENFORCED not-null constraint, since it cannot be validated currently.
* PRIMARY KEY, SERIAL and IDENTITY columns cannot use not enforced
not-null constraint.
* ALTER CONSTRAINT ... [NOT] ENFORCED syntax is not supported for
not-null constraint currently.
* DROP NOT NULL removes a NOT ENFORCED constraint as well.
* ALTER TABLE DROP NOT NULL will drop the not enforced one as well.

Inheritance and partitioning:
* If the parent's constraint is ENFORCED, the child's must be ENFORCED.
* If the parent's constraint is NOT ENFORCED, the child's may be either,
  but the child must still have one.
* A column inheriting conflicting statuses from several parents gets an
  ENFORCED constraint.

commitfest: https://commitfest.postgresql.org/patch/6029
reference:  https://git.postgresql.org/cgit/postgresql.git/commit/?id=a379061a22a8fdf421e1a457cc6af8503def6252
discussion: https://postgr.es/m/CACJufxFbH1_9BDow=4nMSdBfLSOAkiGD5hxO6bouWjZAyHbV+A@mail.gmail.com
-----------------------------------------------



--
jian
https://www.enterprisedb.com/

Attachment

pgsql-hackers by date:

Previous
From: shveta malik
Date:
Subject: Re: Fix "unexpected logical decoding status change" error; from concurrent logical decoding activation
Next
From: Nisha Moond
Date:
Subject: Re: Fix "unexpected logical decoding status change" error; from concurrent logical decoding activation