Re: Support for NO INHERIT to INHERIT state change with named NOT NULL constraints

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Support for NO INHERIT to INHERIT state change with named NOT NULL constraints
Date: 2024-11-19 13:22:43
Message-ID: CACJufxH+m1n2ONa2RFgXGBhWvykOO78RWw7xr4zWS+GP4iAb9g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 15, 2024 at 11:15 AM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>
> On Thu, Nov 14, 2024 at 12:02 AM Suraj Kharage <suraj(dot)kharage(at)enterprisedb(dot)com> wrote:
>>
>> Alvaro stated that allowing a not null constraint state to be modified from INHERIT to NO INHERIT is going to be quite problematic because of the number of weird cases to avoid, so for now that support is not added.
>
> What's the reasoning behind that restriction? What are the weird cases?

current status:
drop table if exists idxpart,idxpart0,idxpart1 cascade;
create table idxpart (a int not null) partition by list (a);
create table idxpart0 (a int constraint foo not null no inherit);

alter table idxpart attach partition idxpart0 for values in (0,1);
ERROR: constraint "foo" conflicts with non-inherited constraint on
child table "idxpart0"

to make it attach to the partition, we need to drop and recreate the
not-null constraint "foo".
that would be very expensive, since recreate, we need to revalidate
the previous row is not null or not.
related post:
https://www.postgresql.org/message-id/202410021219.bvjmxzdspif2%40alvherre.pgsql

with
alter table idxpart0 alter constraint foo inherit;

then we can

alter table idxpart attach partition idxpart0 for values in (0,1);

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2024-11-19 13:23:54 Re: tab_complete for copy(merge
Previous Message Nazir Bilal Yavuz 2024-11-19 13:13:29 Re: meson and check-tests