Unique text index on a non-text column

From: Craig James <cjames(at)emolecules(dot)com>
To: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Unique text index on a non-text column
Date: 2016-07-15 17:26:07
Message-ID: CAFwQ8rdMObVzXTx4Uv-Wnws2aiLaibWm+ADrfActGVBPcT5RUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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?)

Thanks,
Craig

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message David G. Johnston 2016-07-15 17:31:54 Re: Unique text index on a non-text column
Previous Message Alvaro Aguayo Garcia-Rada 2016-07-14 04:48:35 Re: Create extension without superuser