Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ADMIN] Unique text index on a non-text column

1 view
Skip to first unread message

Craig James

unread,
Jul 15, 2016, 1:28:09 PM7/15/16
to
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

David G. Johnston

unread,
Jul 15, 2016, 1:33:50 PM7/15/16
to
​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.

Craig James

unread,
Jul 15, 2016, 1:38:20 PM7/15/16
to
On Fri, Jul 15, 2016 at 10:31 AM, David G. Johnston <david.g....@gmail.com> wrote:
On Fri, Jul 15, 2016 at 1:26 PM, Craig James <cja...@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".

Ah, I'd overlooked that.
 

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

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

Thanks, that did the trick.

Craig


David J.



--
---------------------------------
Craig A. James
Chief Technology Officer
eMolecules, Inc.
---------------------------------
0 new messages