| From: | Dawid Kuroczko <qnex42(at)gmail(dot)com> |
|---|---|
| To: | Andrus <eetasoft(at)online(dot)ee> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: How to create unique constraint on NULL columns |
| Date: | 2005-07-18 15:00:15 |
| Message-ID: | 758d5e7f05071808007dfffacb@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On 7/18/05, Dawid Kuroczko <qnex42(at)gmail(dot)com> wrote:
> On 7/18/05, Andrus <eetasoft(at)online(dot)ee> wrote:
> > I have meaningful primary key in department table (department code used
> > inside enterptise), not a surrogate number (I use meaningful primary keys
> > whenever possible).
>
> OK, so then just define the UNIQUE INDEX to be exactly what you need,
> for example:
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.
Regards,
Dawid
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Joe Maldonado | 2005-07-18 15:04:28 | Re: TRUNCATE locking problem |
| Previous Message | Tom Lane | 2005-07-18 14:56:20 | Re: Changes to not deferred FK in 8.0.3 to 7.4? |