Created
March 23, 2016 00:01
-
-
Save daroczig/c4e4fb427a009c2a0dd9 to your computer and use it in GitHub Desktop.
Update column definitions in Redshift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- create a new temp table with exact same schema | |
CREATE TABLE foobar_temp (LIKE foobar INCLUDING DEFAULTS); | |
-- or create this temp table with any new schema (eg updated col type) | |
CREATE TABLE foobar_temp (...) | |
-- copy everything from old table | |
INSERT INTO foobar_temp <list of columns> SELECT <list of columns> FROM foobar; | |
-- rename/drop tables | |
ALTER TABLE foobar RENAME TO foobar_old; | |
ALTER TABLE foobar_temp RENAME TO foobar; | |
DROP TABLE foobar_old; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment