Skip to content

Instantly share code, notes, and snippets.

@daroczig
Created March 23, 2016 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daroczig/c4e4fb427a009c2a0dd9 to your computer and use it in GitHub Desktop.
Save daroczig/c4e4fb427a009c2a0dd9 to your computer and use it in GitHub Desktop.
Update column definitions in Redshift
-- 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