From: Dmitry Ruban <dmitry@ruban.biz>
To: pgsql-sql@postgresql.org
Subject: unique index on fields with possible null values
Date: Fri, 27 Jul 2007 12:59:38 +1200
Message-ID: <248746715.20070727125938@ruban.biz> (raw)
Hello pgsql-sql,
I'm trying to find a solution for unique index on fields with possible
null values.
Example table:
CREATE TABLE test (
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@ruban.biz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: dmitry@ruban.biz
Subject: Re: unique index on fields with possible null values
In-Reply-To: <248746715.20070727125938@ruban.biz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox