ALTER TABLE,在PostgreSQL 9.1的not null列中设置null


95

我有一个不包含空列的表,如何在此列中将空值设置为默认值?

我的意思是,我想做这样的事情:

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

但它显示:

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;

Answers:




13
First, Set :
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;

11
来到这里寻找如何将列设置为NOT NULL。通过您的回答,我可以找到解决方案:ALTER TABLE person ALTER COLUMN phone SET NOT NULL。谢谢!
falsarella 2015年

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.