Re: Potential bug: Enforcing/not enforcing a CHECK constraint fails on an empty table - Mailing list pgsql-bugs

From Erki Eessaar
Subject Re: Potential bug: Enforcing/not enforcing a CHECK constraint fails on an empty table
Date
Msg-id DB9PR01MB10380E2C3C0CE943C3035AD37FEE6A@DB9PR01MB10380.eurprd01.prod.exchangelabs.com
Whole thread Raw
In response to Re: Potential bug: Enforcing/not enforcing a CHECK constraint fails on an empty table  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-bugs
Hello

Thank you for finding those commit messages; that clarifies the current implementation perfectly.

I agree that adding this limitation to the documentation would be very helpful.

Looking ahead, I hope that support for altering  CHECK constraints can be added. Aligning their behavior with FOREIGN KEY  constraints would make the system more consistent and intuitive for users.

Best regards
Erki Eessaar


From: David Rowley <dgrowleyml@gmail.com>
Sent: Wednesday, October 1, 2025 08:24
To: Erki Eessaar <erki.eessaar@taltech.ee>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: Potential bug: Enforcing/not enforcing a CHECK constraint fails on an empty table
 
On Wed, 1 Oct 2025 at 01:12, Erki Eessaar <erki.eessaar@taltech.ee> wrote:
> However, the inconsistency I'm pointing out is that this "documentation-only" state appears to be modifiable for FOREIGN KEY constraints (using ALTER TABLE ... ENFORCED), but not for CHECK constraints.
>
> This leads to the core of my question: Is this difference in behavior intentional?

At least going by the commit messages, it seems to be intentional:

From [1]:
Note that CHECK constraints do not currently support ALTER operations,
so changing the enforceability of an existing constraint isn't
possible without dropping and recreating it.  This could be added
later.

And for foreign keys in [2]:
Conversely, if a NOT ENFORCED
foreign key constraint is changed to ENFORCED, the necessary triggers
will be created, and the will be changed to VALID by performing
necessary validation.

> If NOT ENFORCED constraints are not meant to be altered after creation, then it seems the ability to enforce a foreign key is the unexpected behavior. If they are meant to be alterable, then the failure to enforce a check constraint seems to be the bug.

I think it would be good if the documents were to mention the
limitation with CHECK constraints. Otherwise, users are just going to
be left to discover this for themselves.

David

[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=ca87c415e
[2] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=eec0040c4

pgsql-bugs by date:

Previous
From: Virender Singla
Date:
Subject: Revoke role membership does not remove cascade privileges
Next
From: Peter Dyballa
Date:
Subject: Re: BUG #19062: PostgreSQL 12.22 does not compile because of conflicting types for CollationCreate