Reject ADD CONSTRAINT NOT NULL if name mismatches existing domain not-null constraint - Mailing list pgsql-hackers

From jian he
Subject Reject ADD CONSTRAINT NOT NULL if name mismatches existing domain not-null constraint
Date
Msg-id CACJufxEcTx2U8tQTcJ2g490wzd=jQgJNDpNb2L+f3gr9J=cpNA@mail.gmail.com
Whole thread
Responses Re: Reject ADD CONSTRAINT NOT NULL if name mismatches existing domain not-null constraint
List pgsql-hackers
Hi.

Similar to https://git.postgresql.org/cgit/postgresql.git/commit/?id=96e2af605043974137d84edf5c0a24561956919e
We apply this logic to the domain not-null constraint too.
It would error out if ALTER DOMAIN ADD CONSTRAINT NOT NULL, the new
constraint name does not
matches the existing domain's not-null constraint

create domain d1 as int constraint nn not null;
src4=# alter domain d1 add constraint nn1 not null;
ERROR:  cannot create not-null constraint "nn1" for domain "d1"
DETAIL:  A not-null constraint named "nn" already exists for domain "d1".

However, repeated ALTER DOMAIN SET NOT NULL or ALTER DOMAIN ADD NOT
NULL statements are allowed,
This aligns with the NOT NULL constraints on tables.

No need to worry about CREATE DOMAIN.
We already disallow multiple NOT NULL constraints in CREATE DOMAIN.
Like this would fail:
create domain d2 as text collate "C" constraint nn not null constraint
nn2 not null;




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

Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Unlogged rel fake lsn vs GetVictimBuffer()
Next
From: vignesh C
Date:
Subject: Re: Skipping schema changes in publication