Re: unique constraint with a null column?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: CSN <cool_screen_name90001(at)yahoo(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: unique constraint with a null column?
Date: 2005-12-30 21:41:33
Message-ID: 20051230214133.GA11704@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Dec 30, 2005 at 13:30:40 -0800,
CSN <cool_screen_name90001(at)yahoo(dot)com> wrote:
> I have three columns, and one of them can be null. I'd
> like to create a unique constraint across all three
> columns and allow only one null value. e.g.
>
> a|b|c
> abc|123|null
> abc|123|null # not allowed
> abc|456|null
> abc|456|987
> abc|456|876
> def|456|null
> def|456|null # not allowed
>
> Currently, the 'not allowed' lines are allowed.

That is how 'unique' constraints are supposed to work. One possible
solution is to use some normal value instead of 'NULL' to represent
that fact.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ubence Quevedo 2005-12-30 21:53:55 Correct way to set up Variables [Was - Simple Accumulating Number Loop?]
Previous Message CSN 2005-12-30 21:40:55 Re: unique constraint with a null column?