From: Jeff Frost <jeff@frostconsultingllc.com>
To: Phillip Tornroth <ptornroth@intellidot.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Multi-Column Constraints and Null Values
Date: Sat, 29 Apr 2006 13:14:36 -0700 (PDT)
Message-ID: <Pine.LNX.4.64.0604291314040.9581@discord.dyndns.org> (raw)
In-Reply-To: <303D0B49-F8EC-491C-8865-B7B819120C13@intellidot.net>
References: <303D0B49-F8EC-491C-8865-B7B819120C13@intellidot.net>
On Thu, 27 Apr 2006, Phillip Tornroth wrote:
> I have a problem in a number of my tables. I'd like to add uniqueness
> constraints across multiple columns, but some of the columns are nullable.
> This gives me trouble since when I create a constraint on columns A and B..
> I'd like the constraint to be enforced such that you couldn't insert values
> ("value for A", null) twice. I understand why the constraints work this way,
> but I'm wondering if anyone knows of a workaround.
>
Phill,
You likely want a multicolumn unique index created like so:
CREATE UNIQUE INDEX foo_A_B_unique_idx ON foo (A,B);
See the docs here:
http://www.postgresql.org/docs/current/interactive/indexes-unique.html
--
Jeff Frost, Owner <jeff@frostconsultingllc.com>
Frost Consulting, LLC http://www.frostconsultingllc.com/
Phone: 650-780-7908 FAX: 650-649-1954
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: jeff@frostconsultingllc.com, ptornroth@intellidot.net
Subject: Re: Multi-Column Constraints and Null Values
In-Reply-To: <Pine.LNX.4.64.0604291314040.9581@discord.dyndns.org>
References: <303D0B49-F8EC-491C-8865-B7B819120C13@intellidot.net> <Pine.LNX.4.64.0604291314040.9581@discord.dyndns.org>
* 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