Re: Unique text index on a non-text column

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Unique text index on a non-text column
Дата
Msg-id CAKFQuwZTPtiZvTc7TGTrgEdy9tuuWZQJ5+cJDh6fKquQDTDhKQ@mail.gmail.com
обсуждение исходный текст
Ответ на Unique text index on a non-text column  (Craig James <cjames@emolecules.com>)
Ответы Re: Unique text index on a non-text column  (Craig James <cjames@emolecules.com>)
Список pgsql-admin
On Fri, Jul 15, 2016 at 1:26 PM, Craig James <cjames@emolecules.com> wrote:
I'd like to enforce text uniqueness on a non-text column (it's of type "molecule" from a third-party plugin). The third-party plugin doesn't support unique indexes. My guess was something like this, but it doesn't work:

create table molecules(id integer primary key, moltext molecule('my-type'));
create unique index i_unique_molecule on molecules(moltext::text);

The "molecule" column does contain an ordinary string, and when selected returns ordinary text data.

Is there a way to do this? (And if so, what did I miss in the documentation?)


​It helps to show what "doesn't work" actually is.


Note the extra set of paretheses surrounding "expression".

​create unique index i_unique_molecule on molecules ((cast(moltext as text)))

((moltext::text)) might work...

David J.

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

Предыдущее
От: Craig James
Дата:
Сообщение: Unique text index on a non-text column
Следующее
От: Craig James
Дата:
Сообщение: Re: Unique text index on a non-text column