Re: not null constraints, again

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tender Wang <tndrwang(at)gmail(dot)com>
Subject: Re: not null constraints, again
Date: 2024-11-07 19:16:32
Message-ID: 202411071916.y77iq5yz5ixr@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2024-Nov-07, jian he wrote:

> drop table if exists part, part0 cascade;
> create table part (a int not null) partition by range (a);
> create table part0 (a int not null);
> alter table part attach partition part0 for values from (0) to (1000);
> alter table ONLY part0 add primary key(a);
> alter table part alter column a drop not null;
>
> as the example shows that part0 not-null constraint is still there.
> that means:
>
> perform <literal>DROP NOT NULL</literal> on the parent table
> will not drop the <literal>NOT NULL</literal> constraint from all partitions.
>
> so we need rephrase the following sentence:
>
> To drop the <literal>NOT NULL</literal> constraint from all the
> partitions, perform <literal>DROP NOT NULL</literal> on the parent
> table.
>
> to address this kind of corner case?

I've been mulling over this and I'm not very sure I want to change the
docs over this point. I think it's fine to leave it as is; otherwise it
becomes too verbose for a very esoteric corner case that has (what I
think is) an obvious explanation: the primary key in the child table
requires that the not-null constraint remains, so it does. Do you
disagree?

Here's v11, which I intended to commit today, but didn't get around to.
CI is happy with it, so I'll probably do it tomorrow first thing.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"I'm impressed how quickly you are fixing this obscure issue. I came from
MS SQL and it would be hard for me to put into words how much of a better job
you all are doing on [PostgreSQL]."
Steve Midgley, http://archives.postgresql.org/pgsql-sql/2008-08/msg00000.php

Attachment Content-Type Size
v11-0001-Add-pg_constraint-rows-for-not-null-constraints.patch text/x-diff 329.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2024-11-07 19:19:32 Re: Avoiding superfluous buffer locking during nbtree backwards scans
Previous Message Robert Haas 2024-11-07 19:00:20 Re: magical eref alias names