Postgres-enum

-- 1. rename the enum type you want to change
alter type some_enum_type rename to _some_enum_type;
-- 2. create new type
create type some_enum_type as enum ('old', 'values', 'and', 'new', 'ones');
-- 3. rename column(s) which uses our enum type
alter table some_table rename column some_column to _some_column;
-- 4. add new column of new type
alter table some_table add some_column some_enum_type not null default 'new';
-- 5. copy values to the new column
update some_table set some_column = _some_column::text::some_enum_type;
-- 6. remove old column and type
alter table some_table drop column _some_column;
drop type _some_enum_type;

中文官网:http://pgguide.lxneng.com/sexy/enums.html

查看枚举:

select t.typname, e.enumlabel from pg_type t, pg_enum e

 

posted @ 2016-10-19 14:48  盖瑞  阅读(319)  评论(0编辑  收藏  举报