Skip to content

Instantly share code, notes, and snippets.

@Capncavedan
Created July 7, 2015 21:07
Show Gist options
  • Save Capncavedan/2d6e62a287007aef5b32 to your computer and use it in GitHub Desktop.
Save Capncavedan/2d6e62a287007aef5b32 to your computer and use it in GitHub Desktop.
moving columns in a table in postgres
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