Обсуждение: Alter table not correct for Postgres 8.0+

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

Alter table not correct for Postgres 8.0+

От
Gary Doades
Дата:
If I try to add a column that is not null with a default the SQL that 
gets generated is:

ALTER TABLE control   ADD COLUMN security_options int;
ALTER TABLE control   ALTER COLUMN security_options SET NOT NULL;
ALTER TABLE control   ALTER COLUMN security_options SET DEFAULT 32;

This generates an error if the table already contains rows.

Whereas from 8.0 the following will work and ought to be used instead:

ALTER TABLE control   ADD COLUMN security_options int not null default 32;


Thanks,
Gary.