Re: [PG19] Three bugs with a CHECK constraint that only the child enforces

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Nikolay Samokhvalov <nik(at)postgres(dot)ai>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Subject: Re: [PG19] Three bugs with a CHECK constraint that only the child enforces
Date: 2026-10-12 08:44:08
Message-ID: CACJufxGjGGuEezE78cwt_T+0PTdk6sBA7X=kUqkJArs=3iZnbw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Oct 9, 2026 at 12:42 PM shihao zhong <zhong950419(at)gmail(dot)com> wrote:
>
> Hi hackers,
>
> I used Opus to analyze the new features in PG19, and it found three
> bugs with a CHECK constraint that a child enforces and its parent
> does not. Each item has a script and a patch with its number.
> "Before" is 19 and master today. "After" is with the patch, and is
> the output I expect.
>
> 3. pg_dump prints only the parent's definition, so the child is NOT
> ENFORCED after a restore. pg_upgrade is fine.
>
> create table p3 (a int, constraint c check (a > 0) not enforced);
> create table k3 () inherits (p3);
> alter table k3 alter constraint c enforced;
> Before, pg_dump -s has:
> ALTER TABLE public.p3
> ADD CONSTRAINT c CHECK ((a > 0)) NOT ENFORCED;
> After 0003, it also has:
> ALTER TABLE public.k3 ALTER CONSTRAINT c ENFORCED;

Hi.
Let pg_dump produce ALTER CONSTRAINT seems weird.
We can let pg_dump produce inline constraint (within CREATE TABLE
statement) or ALTER TABLE ADD CONSTRAINT, see the attached.

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

Attachment Content-Type Size
v2-0001-pg_dump-keep-child-table-CHECK-constraint-status.txt text/plain 8.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2026-10-12 09:17:42 Re: [PG19] Wrong results from NOT NULL-based expression simplification
Previous Message Jakub Wartak 2026-10-12 08:42:49 Re: Reduce logging during prepared transaction recovery