Redshift - How to remove NOT NULL constraint?

后端 未结 3 1388
星月不相逢
星月不相逢 2021-02-12 22:45

Since Redshift does not support ALTER COLUMN, I would like to know if it\'s possible to remove the NOT NULL constraints from columns in Redshift.

3条回答
  •  太阳男子
    2021-02-12 23:07

    You cannot alter the table.

    There is an alternative approach. You can create a new column with NULL constraint. Copy the values from your old column to this new column and then drop the old column.

    Something like this:

    ALTER TABLE table1 ADD COLUMN somecolumn (definition as per your reqm);
    UPDATE table1 SET somecolumn = oldcolumn;
    ALTER TABLE table1 DROP COLUMN oldcolumn;
    ALTER TABLE table1 RENAME COLUMN somecolumn TO oldcolumn;
    

提交回复
热议问题