ALTER TABLE, set null in not null column, PostgreSQL 9.1

Brian Brown picture Brian Brown · Nov 30, 2012 · Viewed 100.5k times · Source

I have a table with not null column, How to set a null value in this column as default?

I mean, I want to do something like this:

postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL;

but it shows:

postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL;
ERROR:  syntax error at or near "NULL"
LINE 1: ALTER TABLE person ALTER COLUMN phone SET NULL;

Answer

a_horse_with_no_name picture a_horse_with_no_name · Nov 30, 2012
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;

More details in the manual: http://www.postgresql.org/docs/9.1/static/sql-altertable.html