Re: Unique index with Null value in one field

Поиск
Список
Период
Сортировка
От Jaime Casanova
Тема Re: Unique index with Null value in one field
Дата
Msg-id c2d9e70e0510120724h59f19af6kb86678981229899@mail.gmail.com
обсуждение исходный текст
Ответ на Unique index with Null value in one field  (Hrishi Joshi <hjoshi@abcsinc.com>)
Список pgsql-general
On 11 Oct 2005 17:36:59 -0500, Hrishi Joshi <hjoshi@abcsinc.com> wrote:
> Hi,
>
> I need to define a Unique index on 3 non-PK fields (composite key) on my
> table in PostgreSQL 8.0.3.
>
> The problem is, if any of those 3 fields is Null, PostgreSQL allows
> duplicate rows to be inserted. While searching through archives, I found
> more information about this.
>
> But I need to know how can I make PostgreSQL throw error on attempt to
> insert second record having same 3 field values, one of them being Null.
>
>
> ------------------------------------------------
> myid |  field1 |  field2 |  field3 | description
> PK   |  <---  Unique Index --->    |
> ------------------------------------------------
> 100  | ABC     | XYZ     | <null>  | Record 1   -> This is ok.
> 101  | ABC     | XYZ     | <null>  | Record 2   -> * This should error!
> ------------------------------------------------
>
> Fields {field1, field2, field3} have unique index on them and "myid" is
> the primary key of my table.
>
>
> Oracle 9i throws exception in such case, but PostgreSQL does not.
>
>
> Thanks,
> - Hrishi Joshi.
>
>

maybe with a function and comparing yourself...

--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

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

Предыдущее
От: "Marc G. Fournier"
Дата:
Сообщение: Re: [pgsql-advocacy] Oracle buys Innobase
Следующее
От: Brian Mathis
Дата:
Сообщение: PG 8.0.4, Centos and 64 bit