Skip to content

Instantly share code, notes, and snippets.

@zph
Forked from mmasashi/update_column_type.sql
Created September 8, 2016 21:25
Show Gist options
  • Save zph/9c5be4518842dd9b22eb659890d0ff11 to your computer and use it in GitHub Desktop.
Save zph/9c5be4518842dd9b22eb659890d0ff11 to your computer and use it in GitHub Desktop.
How to change the column type for Redshift.
BEGIN;
LOCK table_name;
ALTER TABLE table_name ADD COLUMN column_new column_type;
UPDATE table_name SET column_new = column_name;
ALTER TABLE table_name DROP column_name;
ALTER TABLE table_name RENAME column_new TO column_name;
END;
-- varchar -> integer
-- UPDATE cpvbeacon_dev SET column_new = CAST (nullif(column_name, '') AS INTEGER);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment