Created
July 11, 2017 18:53
-
-
Save dylanpyle/d55689920971d95d4eabe7aa52897756 to your computer and use it in GitHub Desktop.
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
-- context: we have a table `animals` with a column `animal_type` | |
-- this column has an enum value of ('human', 'cat', 'dog') - a.k.a. `possible_animal_types` | |
-- we want to remove the 'dog' possibility from the enum type | |
-- this is a simplified case too; my actual code is much longer as i'm using this type in a few tables | |
-- is there a better/easier way?? | |
alter table animals | |
alter column animal_type type text, | |
alter column animal_type set default 'human'; | |
drop type possible_animal_types; | |
create type possible_animal_types as enum ('human', 'cat'); | |
alter table animals | |
alter column animal_type set default 'human'::possible_animal_types; | |
alter table animals | |
alter column animal_type type possible_animal_types using animal_type::possible_animal_type; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment