public inbox for [email protected]  
help / color / mirror / Atom feed
From: Robert Treat <[email protected]>
To: jian he <[email protected]>
Cc: PostgreSQL-development <[email protected]>
Subject: Re: alter check constraint enforceability
Date: Wed, 6 Aug 2025 19:35:08 -0400
Message-ID: <CABV9wwNF45wmhs3gFH7qcyEVQjREQL1y=2ARzLgY__fNT2tWpw@mail.gmail.com> (raw)
In-Reply-To: <CACJufxFJFpU0V6zW6nic8_K9NOZqu1g5MOuuSRPTJ9xSAmeNrw@mail.gmail.com>
References: <CACJufxHCh_FU-FsEwsCvg9mN6-5tzR6H9ntn+0KUgTCaerDOmg@mail.gmail.com>
	<CACJufxFJFpU0V6zW6nic8_K9NOZqu1g5MOuuSRPTJ9xSAmeNrw@mail.gmail.com>

On Fri, Jul 4, 2025 at 8:00 AM jian he <[email protected]> wrote:
>
> On Mon, Jun 2, 2025 at 9:57 PM jian he <[email protected]> wrote:
> >
> > Currently in pg18, we can add not enforced check constraints.
> > but we can not do  ALTER TABLE ALTER CONSTRAINT [NOT] ENFORCED
> > for check constraint.
> >
> > The attached patch is implementation of changing enforceability of
> > check constraint.
>

Initial look and testing looks good. There are some odd parts to work
through with partitioned tables and recursion (for example, if you
have a parent unenforced, and a child enforced, setting a parent
enforced and then not enforced will recurse to the child, so you end
up in a different state. that could be surprising, but the alternative
is not obviously more sensicle).

Some minor items below:

+ errhint("Only foreign key, check constraint can change enforceability"));

"Only foreign key and check constraints can change enforceability"

--

+ /*
+ * If we are told not to recurse, there had better not be any child
+ * tables, because we can't changing constraint enforceability on
+ * the parent unless we have chaned enforceability for all child
+ * tables.
+ */

* tables, because we can't change constraint enforceability on
* the parent unless we have changed enforceability for all child

-- 

+ if (rel->rd_rel->relkind == RELKIND_RELATION &&
+     cmdcon->is_enforced &&
+     !currcon->conenforced)

i think I have convinced myself that this is correct, but maybe I will
ask you if you had any concerns that this needed to also consider
RELKIND_PARTITIONED_TABLE as well?


Robert Treat
https://xzilla.net





view thread (13+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: alter check constraint enforceability
  In-Reply-To: <CABV9wwNF45wmhs3gFH7qcyEVQjREQL1y=2ARzLgY__fNT2tWpw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox