ENUM drop label workaround

Поиск
Список
Период
Сортировка
От Sergey Konoplev
Тема ENUM drop label workaround
Дата
Msg-id CAL_0b1tkeM_O=pt5cFbb4fnKbJg-bzw-X21KoK0P4rEMTLQNqQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: ENUM drop label workaround  (Arjen Nienhuis <a.g.nienhuis@gmail.com>)
Список pgsql-general
Hi,

AIU we have no ability to drop a label from ENUM currently, and there
are no plans to add this feature in the nearest future.

I came to a workaround via DOMAIN, here it is:

CREATE TYPE ref AS ENUM ('aaa', 'bbb');

CREATE DOMAIN refdom AS ref DEFAULT 'aaa';

ALTER TABLE table1 ADD refdom_column refdom;

ALTER DOMAIN refdom ADD CONSTRAINT refdom_deleted_chk
CHECK (VALUE NOT IN ('bbb'));

UPDATE table1 SET refdom_column = 'bbb';
ERROR:  value for domain refdom violates check constraint "refdom_deleted_chk"

UPDATE table1 SET refdom_column = 'ccc';
ERROR:  invalid input value for enum ref: "ccc"

Are there any caveats of this solution and may be there is a better one?

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray.ru@gmail.com


В списке pgsql-general по дате отправления:

Предыдущее
От: Augori
Дата:
Сообщение: Re: Trouble installing psycopg2
Следующее
От: David Kerr
Дата:
Сообщение: Re: Trouble installing psycopg2