Обсуждение: adding not null constraint to existing table

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

adding not null constraint to existing table

От
Alex Howansky
Дата:
What's the simplest way to add a not null constraint to a field in an existing
table? It doesn't seem that alter table supports it -- that I'll have to create
a new table and copy into it. Is that correct? TIA,

--
Alex Howansky
Wankwood Associates
http://www.wankwood.com/


Re: adding not null constraint to existing table

От
Stephan Szabo
Дата:
On Fri, 2 Feb 2001, Alex Howansky wrote:

>
> What's the simplest way to add a not null constraint to a field in an existing
> table? It doesn't seem that alter table supports it -- that I'll have to create
> a new table and copy into it. Is that correct? TIA,

You can also do something to the system catalogs as a superuser to set
attnotnull to true in pg_attribute for the particular attribute you want.

Something like:
update pg_attribute set attnotnull='t' where
pg_attribute.attrelid=pg_class.oid and pg_class.relname=<table> and
attname=<attribute>;