Обсуждение: Case insensitive unique constraint

Поиск
Список
Период
Сортировка

Case insensitive unique constraint

От
Michael Rowan
Дата:
HI

I would like to do this:
ALTER TABLE a ADD CONSTRAINT a_unique UNIQUE lower(name)

This fails, syntax error near "lower"

This succeeds:
ALTER TABLE a ADD CONSTRAINT a_unique UNIQUE name

Can I get what I want, and if so, how?  Many thanks.

Mike

Re: Case insensitive unique constraint

От
Tom Lane
Дата:
Michael Rowan <michael.rowan3@gmail.com> writes:
> I would like to do this:
> ALTER TABLE a ADD CONSTRAINT a_unique UNIQUE lower(name)

You can't get to that through CONSTRAINT syntax, but you can just
create a unique index directly:

CREATE UNIQUE INDEX a_unique ON a (lower(name))

            regards, tom lane