I have a database which contains more than 30m records, and I need to add two new columns to the database. The problem is that I need these columns to be NOT NULL, and without a default value. I thought that I would just add these columns without the NOT NULL constraint, fill them with data, then add the constraint, but Redshift doesn't support that. I have an other solution in my mind, but I wonder if there is any more simpler solution than this?
- Create the two new columns with NOT NULL and DEFAULT
- Filling the columns with data
- Creating an empty table with the same columns as the target DB. (Of course the two new columns would be just NOT NULL)
- Inserting everything from the target DB to the new DB.
- Dropping the target DB
- Renaming the new DB to the target.