Re: ALTER TABLE ADD COLUMN can't use NOT NULL? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: ALTER TABLE ADD COLUMN can't use NOT NULL?
Date
Msg-id 15801.1005586609@sss.pgh.pa.us
Whole thread Raw
In response to ALTER TABLE ADD COLUMN can't use NOT NULL?  (Bradley McLean <brad@bradm.net>)
Responses Re: ALTER TABLE ADD COLUMN can't use NOT NULL?
List pgsql-hackers
Bradley McLean <brad@bradm.net> writes:
> In the CVS tip from this morning:
> a123=# alter table test add test1 int4 not null;
> ERROR:  Adding NOT NULL columns is not implemented.
>         Add the column, then use ALTER TABLE ADD CONSTRAINT.

> I'm pretty sure the first one used to work just fine.

No, it never worked per spec.  The spec requires the constraint to
be enforced immediately, and since the values of the new column
would all be null, there's no way for this to be a legal command.

What's legal per spec is an ADD that provides a DEFAULT along with
specifying NOT NULL.  But we don't support ADD with a DEFAULT yet :-(
        regards, tom lane


pgsql-hackers by date:

Previous
From: Bradley McLean
Date:
Subject: ALTER TABLE ADD COLUMN can't use NOT NULL?
Next
From: mlw
Date:
Subject: rename index?