Re: How to create unique constraint on NULL columns

From: "Andrus" <eetasoft(at)online(dot)ee>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to create unique constraint on NULL columns
Date: 2005-07-18 17:02:30
Message-ID: dbgner$5c1$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Or better:
> CREATE UNIQUE INDEX permission_unique_key
> (user_id,permission_id,department_id);
> CREATE UNIQUE INDEX permission_uninull_key (user_id,permission_id)
> WHERE department_id IS NULL;
>
> ...you may want to add WHERE department_id IS NOT NULL to the first query
> (or not). Anyway -- this way these indexes could be used by searches
> easily
> than using previous index I've sent.
>

Dawid,

I see no difference of adding/not adding IS NOT NULL to the first CREATE
UNIQUE INDEX .
So why the explicit creation of first unique index is required ?

It would be better to create unique constraint on
(user_id,permission_id,department_id) instead on explicity creating index.

Andrus.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-07-18 17:29:47 Re: How to create unique constraint on NULL columns
Previous Message Andrus 2005-07-18 16:53:24 Re: How to find the number of rows deleted