Redshift - How to remove NOT NULL constraint?

后端 未结 3 1394
星月不相逢
星月不相逢 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:30

    The accepted answer can produce an error:

    cannot drop table  column  because other objects depend on it
    

    Adding CASCADE at the end of the DROP COLUMN statement will fix this, however it can have the unwanted side effect of dropping other tables if they are dependent on it.

    ALTER TABLE table1 ADD COLUMN newcolumn (definition as per your reqirements);
    UPDATE table1 SET newcolumn = oldcolumn;
    ALTER TABLE table1 DROP COLUMN oldcolumn CASCADE;
    ALTER TABLE schema_name.table1 RENAME COLUMN newcolumn TO oldcolumn;
    

    I found this information here, when the accepted answer wasn't working for me: https://forums.aws.amazon.com/message.jspa?messageID=463248

    Also note: When I tried to rename the column, I got another error: relation does not exist

    To fix that, I added the schema name in front of the table name in the RENAME COLUMN statement

提交回复
热议问题