Skip to content
Advertisement

Redshift – How to remove NOT NULL constraint?

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.

Advertisement

Answer

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;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement