Re: How to create unique constraint on NULL columns - Mailing list pgsql-general

From Andrus
Subject Re: How to create unique constraint on NULL columns
Date
Msg-id dbgner$5c1$1@news.hub.org
Whole thread Raw
In response to Re: How to create unique constraint on NULL columns  (Bruno Wolff III <bruno@wolff.to>)
List 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.



pgsql-general by date:

Previous
From: "Andrus"
Date:
Subject: Re: How to find the number of rows deleted
Next
From: Scott Marlowe
Date:
Subject: Re: How to find the number of rows deleted