Re: NOT NULL NOT ENFORCED

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Sebas Mannem <sebas(at)mannem(dot)nl>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: NOT NULL NOT ENFORCED
Date: 2026-09-28 05:03:24
Message-ID: CACJufxECCgByCscWPCKCmHtW1f9Riz7S72sQ0HzDht3VQEoWfw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 11, 2026 at 2:47 PM Sebas Mannem <sebas(at)mannem(dot)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 Content-Type Size
v6-0001-NOT-NULL-NOT-ENFORCED.patch text/x-patch 88.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nisha Moond 2026-09-28 05:03:36 Re: Fix "unexpected logical decoding status change" error; from concurrent logical decoding activation
Previous Message shveta malik 2026-09-28 05:00:02 Re: Fix "unexpected logical decoding status change" error; from concurrent logical decoding activation