On 2024-Feb-05, Alvaro Herrera wrote:
> While playing with it I noticed this other behavior change from 16,
>
> create table pa (a int primary key) partition by list (a);
> create table pe (a int unique);
> alter table pa attach partition pe for values in (1, null);
>
> In 16, we get the error:
> ERROR: column "a" in child table must be marked NOT NULL
> which is correct (because the PK requires not-null). In master we just
> let that through, but that seems to be a separate bug.
Hmm, so my initial reaction was to make the constraint-matching code
ignore the constraint in the partition-to-be if it's not the same type
(this is what patch 0002 here does) ... but what ends up happening is
that we create a separate, identical constraint+index for the primary
key. I don't like that behavior too much myself, as it seems too
magical and surprising, since it could cause the ALTER TABLE ATTACH
operation of a large partition become costly and slower, since it needs
to create an index instead of merely scanning the whole data.
I'll look again at the idea of raising an error if the not-null
constraint is not already present. That seems safer (and also, it's
what we've been doing all along).
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/