Skip site navigation (1) Skip section navigation (2)

unique index on fields with possible null values

From: Dmitry Ruban <dmitry(at)ruban(dot)biz>
To: pgsql-sql(at)postgresql(dot)org
Subject: unique index on fields with possible null values
Date: 2007-07-27 00:59:38
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Hello pgsql-sql,

I'm trying to find a solution for unique index on fields with possible
null values.

Example table:

 a integer NOT NULL,
 b integer NULL

As long as unique index can't check if there are records with null
values i found the only one solution for this problem:

CREATE UNIQUE INDEX test_uniq1 ON test (a, COALESCE(b,0));

Are there any other ways of doing this?

Best regards,
 Dmitry                          mailto:dmitry(at)ruban(dot)biz


pgsql-sql by date

Next:From: Paul LambertDate: 2007-07-27 01:33:20
Subject: Join question
Previous:From: Harald Armin MassaDate: 2007-07-26 15:17:03
Subject: Re: Tunning PostgreSQL performance for views on Windows

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group