Re: unique constraint with significant nulls?

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Mike Blackwell <mike(dot)blackwell(at)rrd(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: unique constraint with significant nulls?
Date: 2012-09-25 15:32:57
Message-ID: 20120925153257.GA20437@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Sep 25, 2012 at 10:05:15AM -0500, Mike Blackwell wrote:
> How would one go about building a multi-column unique constraint where null
> is a significant value, eg. (1, NULL) <> (2, NULL)?
>
> I see a number of references to not being able to use an index for this,
> but no mention of an alternative. Any pointers would be appreciated

create unique index zzz on table ((column is null), coalesce(column, 'whatever'));

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
http://depesz.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Igor Neyman 2012-09-25 15:39:41 Re: Running CREATE only on certain Postgres versions
Previous Message Daniele Varrazzo 2012-09-25 15:25:41 Re: Running CREATE only on certain Postgres versions