Created
July 7, 2015 21:07
-
-
Save Capncavedan/2d6e62a287007aef5b32 to your computer and use it in GitHub Desktop.
moving columns in a table in postgres
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
this guide: https://wiki.postgresql.org/wiki/Alter_column_position#Add_columns_and_move_data | |
alter table financial_statements add column new_years_in_business integer, add column new_other_net_worth integer; | |
update financial_statements set new_years_in_business = years_in_business; | |
update financial_statements set new_other_net_worth = other_net_worth; | |
alter table financial_statements drop column years_in_business cascade, drop column other_net_worth cascade; | |
alter table financial_statements rename column new_years_in_business to years_in_business; | |
alter table financial_statements rename column new_other_net_worth to other_net_worth; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment