| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | ALTER COLUMN SET NOT NULL differ from ALTER TABLE ADD CONSTRAINT |
| Date: | 2026-10-19 13:30:00 |
| Message-ID: | CACJufxGm_97F-iELOrOzXbv-gzV4fr0VjhfdikSys1pA=7JXJw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi.
While trying to check
https://git.postgresql.org/cgit/postgresql.git/commit/?id=96e2af605043974137d84edf5c0a24561956919e
potential pg_dump output related bug.
I encountered the following issue first.
I expect ALTER TABLE ADD CONSTRAINT to have the same effect as ALTER COLUMN SET
NOT NULL, meaning that the column associated constraint will be marked as VALID
and ENFORCED across the entire table inheritance hierarchy.
I think it is ok for one form to fail (error out) while the other succeeds.
However, if ALTER COLUMN SET NOT NULL succeeds, all associated NOT NULL
constraints should be marked as VALID and ENFORCED.
drop table if exists tp, tc cascade;
create table tp (a int);
create table tc (a int) inherits (tp);
alter table tc add constraint nn not null a not valid;
alter table tp add constraint nn not null a; -- error
alter table tp alter column a set not null; -- should expect an error
The last ALTER COLUMN SET NOT NULL should either error out or make the column
'a' in table "tc" have a not-null constraint that is ENFORCED and VALID?
The partitioned table has a similar issue.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David Geier | 2026-10-19 13:31:32 | Re: Reducing relcache memory usage 2: shrink sizeof(RelationData) |
| Previous Message | Henson Choi | 2026-10-19 13:27:25 | Re: Row pattern recognition |