Re: NOT NULL NOT ENFORCED

From: Sebas Mannem <sebas(at)mannem(dot)nl>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: NOT NULL NOT ENFORCED
Date: 2026-09-11 06:47:27
Message-ID: E4FK57YYN4wTz9_ExrhZVlf9oCdmiIgMZk2av73brzfGnUlJb-cJt9c9sPhqpwnJeUvF9-5xTdWyFh5zWnzJvPITyfAfVAIW8dwPeS386BY=@mannem.nl
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,
this commit message could be much clearer on what the patch does.
If you would:
- clearer separation between what the the original code does, and
- align the titles of the blocks
it would really help.

One example:

> attached patch will remove sql_features.txt item F492: "Optional table
> constraint
> enforcement" Comment: "except not-null constraints". see [1]

Something like this would first point to what part of the code this is about
and then what this patch does to it:

Item F492 of sql_features.txt (Optional table constraint enforcement)
has a remark "except not-null constraints", see [1] for more info.
This patch will remove the need for that remark, by adding NOT ENFORCED
as an option for NOT NULL constraints.

Hope this helps.

Sebas Mannem

On Thursday, 10 September 2026 at 10:21, jian he <jian(dot)universality(at)gmail(dot)com> wrote:

> hi.
>
> attached patch will remove sql_features.txt item F492: "Optional table
> constraint
> enforcement" Comment: "except not-null constraints". see [1]
>
> main points about NOT NULL NOT ENFORCED
> * one column can have at most one NOT-NULL constraint, regardless constraints
> property (not enforced or enforced)
> * if column already have not enforced not-null constraint then:
> ALTER TABLE ALTER COLUMN SET NOT NULL: error out, can not validate
> not enforced not-null constraint
> ALTER TABLE ADD NOT NULL: error out, can not add another not-null
> constraint, one column can only have one.
>
> not null in partitioned table:
> * If the partitioned table has an enforced not-null constraint, its partitions
> cannot have not enforced.
> * If the partitioned table has a NOT ENFORCED not-null constraint, its
> partitions may have either ENFORCED or NOT ENFORCED not-null constraints, but
> the constraint itself is still required.
>
> not null in table inheritance:
> OK: parent is not enforced, while child is enforced
> NOT OK: parent is enforced, while child is not enforced
> If a column inherits from multiple tables and the ancestor tables have
> conflicting ENFORCED statuses, raise an error.
>
> I have written extensive tests to cover the corner case, the tests may be
> overwhelming.
>
> [1]: https://www.postgresql.org/docs/devel/features-sql-standard.html
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2026-09-11 07:04:10 Re: Review items for EXCEPT TABLE publication
Previous Message shveta malik 2026-09-11 06:44:16 Re: Crashes on a partition whose concurrent detach never finished