Changing DISTKEY/SORTKEY in an Existing Redshift Table

Redshift does not allow you to change certain table attributes such as the DISTKEY, SORTKEY or ENCODE of an existing table.
In order to change these attributes safely while running AutoLoad or Sync, you can follow the steps below.

ALTER TABLE test_table RENAME TO old_test_table;  CREATE TABLE new_test_table([new table columns]); -- Specify new attributes  INSERT INTO new_test_table (SELECT * FROM old_test_table);  ALTER TABLE new_test_table RENAME TO test_table;  DROP TABLE old_test_table;