Adding a new value to an existing ENUM Type

前端 未结 18 1323
春和景丽
春和景丽 2020-12-04 04:52

I have a table column that uses an enum type. I wish to update that enum type to have an additional possible value. I don\'t want to delete any exi

18条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 05:10

    If you are using Postgres 12 you can just run ALTER TYPE ... ADD VALUE inside of transaction (documentation).

    If ALTER TYPE ... ADD VALUE (the form that adds a new value to an enum type) is executed inside a transaction block, the new value cannot be used until after the transaction has been committed.

    So no hacks needed in migrations.

    UPD: here is an example (thanks to Nick for it)

    ALTER TYPE enum_type ADD VALUE 'new_value';

提交回复
热议问题