Created
October 22, 2013 20:18
-
-
Save mmasashi/7107430 to your computer and use it in GitHub Desktop.
How to change the column type for Redshift.
This file contains hidden or 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
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); |
Wouldn't ALTER commit immediately ? BEGIN...END block is use less here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this changes the order of column names.