Message about not null in ALTER TABLE

Поиск
Список
Период
Сортировка
Искать

Message about not null in ALTER TABLE

От:
Alvaro Herrera <alvherre@atentus.com>
Дата:
I think this is a bug in the error message:

alvherre=> alter table test add column b int not null;
ERROR:  Adding NOT NULL columns is not implemented.
	Add the column, then use ALTER TABLE ADD CONSTRAINT.

However, there is no way to add a NOT NULL constraint to an existing
column in a table, so the error message is misleading.

alvherre=> alter table test add constraint bnotnull not null b;
ERROR:  parser: parse error at or near "not"

-- 
Alvaro Herrera ()
"Siempre hay que alimentar a los dioses, aunque la tierra este seca"
(Orual)

Re: Message about not null in ALTER TABLE

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Alvaro Herrera  writes:
> However, there is no way to add a NOT NULL constraint to an existing
> column in a table, so the error message is misleading.

Sure there is:

regression=# create table test (a int);
CREATE
regression=#  alter table test add column b int not null;
ERROR:  Adding NOT NULL columns is not implemented.
        Add the column, then use ALTER TABLE ADD CONSTRAINT.
regression=#  alter table test add column b int;
ALTER
regression=# alter table test add constraint bnotnull check (b notnull);
ALTER
regression=#

It'd be nice to have more ALTER TABLE variants implemented, but it's
not true that you can't get the functionality nohow...

			regards, tom lane
FAQ