How to delete an enum type value in postgres?

前端 未结 9 2014
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 08:02

How do I delete an enum type value that I created in postgresql?

create type admin_level1 as enum(\'classifier\', \'moderator\', \'god\');

9条回答
  •  有刺的猬
    2020-12-04 08:48

    If you want delete item of enum type, you must operate on system table of PostgreSQL.

    With this command, you can display all the items enum type.

    SELECT * FROM pg_enum;

    Then check that searched the value is unique. To increase the uniqueness during the removal of rekoru must be passed 'enumtypid' in addition to 'enumlabel'.

    This command removes the entry in enum type, where 'unique' is your value.

    DELETE FROM pg_enum en WHERE en.enumtypid=124 AND en.enumlabel='unique';

    NOTE The example that I described must be used, when by chance we add new value to enum type, and yet we have not used it anywhere in database.

提交回复
热议问题