1252748 1252748 - 4 months ago 18
SQL Question

set default value to null on postgresql

I read here that I should be able to set the default value of a column like this:

ALTER [ COLUMN ] column SET DEFAULT expression


But this:

ALTER address.IsActive SET DEFAULT NULL

Gives me this error:




ERROR: syntax error at or near "address" LINE 1: ALTER address.IsActive SET DEFAULT NULL





What have I doe wrong? Also, how can I specify multiple columns to have their default value be
NULL
?

Answer

You're not running the complete statement. You're missing the ALTER TABLE part:

ALTER TABLE [ ONLY ] name [ * ]
    action [, ... ]
ALTER TABLE [ ONLY ] name [ * ]
    RENAME [ COLUMN ] column TO new_column
ALTER TABLE name
    RENAME TO new_name

where action is one of:
[...]

Comments