Re: Howto have a unique restraint on UPPER (textfield)

Поиск
Список
Период
Сортировка
От Joshua Tolley
Тема Re: Howto have a unique restraint on UPPER (textfield)
Дата
Msg-id 4b64f184.9613f30a.5d13.01b2@mx.google.com
обсуждение исходный текст
Ответ на Howto have a unique restraint on UPPER (textfield)  (Andreas <maps.on@gmx.net>)
Ответы Re: Howto have a unique restraint on UPPER (textfield)
Список pgsql-sql
On Sun, Jan 31, 2010 at 03:26:14AM +0100, Andreas wrote:
> Hi,
>
> is there a way to define a unique restraint on UPPER (textfield)?
>
> E.g.  mytable (
>    name_id serial PRIMARY KEY,
>    name varchar(255),
>    UNIQUE ( upper (name) )
> )
>
> psql throws a syntax error because of the upper() function.
>
> I need to prohibit that  2 of strings like   cow, Cow, CoW  appears in
> the name-column.

Like this:

5432 josh@josh# create table c (d text);
CREATE TABLE
5432 josh@josh*# create unique index c_ix on c (upper(d));
CREATE INDEX
5432 josh@josh*# insert into c (d) values ('text');
INSERT 0 1
5432 josh@josh*# insert into c (d) values ('tExt');
ERROR:  duplicate key value violates unique constraint "c_ix"

--
Joshua Tolley / eggyknap
End Point Corporation
http://www.endpoint.com

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

Предыдущее
От: Andreas
Дата:
Сообщение: Howto have a unique restraint on UPPER (textfield)
Следующее
От: msi77
Дата:
Сообщение: Re: Howto have a unique restraint on UPPER (textfield)