X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F0D0F11F629B for ; Sat, 29 Apr 2006 17:15:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 19879-04-2 for ; Sat, 29 Apr 2006 17:14:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp114.sbc.mail.mud.yahoo.com (smtp114.sbc.mail.mud.yahoo.com [68.142.198.213]) by postgresql.org (Postfix) with SMTP id 743EE11F64C7 for ; Sat, 29 Apr 2006 17:14:47 -0300 (ADT) Received: (qmail 94991 invoked from network); 29 Apr 2006 20:14:39 -0000 Received: from unknown (HELO discord.dyndns.org) (jeffroe996@sbcglobal.net@69.226.248.120 with plain) by smtp114.sbc.mail.mud.yahoo.com with SMTP; 29 Apr 2006 20:14:39 -0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by discord.dyndns.org (8.13.6/8.13.4) with ESMTP id k3TKEaWW006793; Sat, 29 Apr 2006 13:14:36 -0700 Date: Sat, 29 Apr 2006 13:14:36 -0700 (PDT) From: Jeff Frost X-X-Sender: jeff@discord.dyndns.org To: Phillip Tornroth cc: pgsql-sql@postgresql.org Subject: Re: Multi-Column Constraints and Null Values In-Reply-To: <303D0B49-F8EC-491C-8865-B7B819120C13@intellidot.net> Message-ID: References: <303D0B49-F8EC-491C-8865-B7B819120C13@intellidot.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/217 X-Sequence-Number: 25026 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 Frost Consulting, LLC http://www.frostconsultingllc.com/ Phone: 650-780-7908 FAX: 650-649-1954