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

From Bruno Wolff III
Subject Re: How to create unique constraint on NULL columns
Date
Msg-id 20050715194909.GA13079@wolff.to
Whole thread Raw
In response to Re: How to create unique constraint on NULL columns  ("Andrus" <eetasoft@online.ee>)
Responses Re: How to create unique constraint on NULL columns
List pgsql-general
On Fri, Jul 15, 2005 at 20:08:32 +0300,
  Andrus <eetasoft@online.ee> wrote:
>
> So I'll think still continuing to use null as unrestricted department
> access.
>
> Is it reasonable to create unique constraint using
>
> CREATE UNIQUE INDEX user_id_permission_id_department_id_unique_idx
>   ON permission (user_id, permission_id, COALESCE(department_id,'ALL'))

If you are going to do this a partial index is a better way to go.
Something like:
CREATE UNIQUE INDEX user_id_permission_id_null ON permission
  WHERE department_id IS NULL;

However either of these let you insert and entry for "ALL" while also
having entries for individual departments.

pgsql-general by date:

Previous
From: "Solange"
Date:
Subject: Re: PostgreSQL 8.0.3
Next
From: Richard_D_Levine@raytheon.com
Date:
Subject: Re: How to create unique constraint on NULL columns