Re: Create unique index or constraint on part of a column

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: Create unique index or constraint on part of a column
Дата
Msg-id il3q4n$n85$1@dough.gmane.org
обсуждение исходный текст
Ответ на Create unique index or constraint on part of a column  (Ruben Blanco <rubenblan@gmail.com>)
Список pgsql-general
Ruben Blanco wrote on 08.03.2011 00:30:
> Hi:
>
> Is there anyway to create a unique index or constraint on part of a column?
>
> Something like this, but something that works ;-)
>
>    ALTER TABLE invoices
>    ADD CONSTRAINT cons UNIQUE (EXTRACT(YEAR FROM invoice_date), innvoice_number);
>
> Thanks for any help.
> Ruben,

CREATE UNIQUE INDEX idx_cons ON invoices (EXTRACT(YEAR FROM invoice_date), innvoice_number);

The only difference to a unique constraint is, that it cannot be used as the target of a foreign key constraint.

Regards
Thomas


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

Предыдущее
От: Ruben Blanco
Дата:
Сообщение: Create unique index or constraint on part of a column
Следующее
От: Glenn Maynard
Дата:
Сообщение: Re: Why count(*) doest use index?