Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id C24E39FB54C for ; Wed, 24 Oct 2007 11:53:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 44294-04 for ; Wed, 24 Oct 2007 11:53:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smaug.vex.net (smaug.vex.net [208.76.104.132]) by postgresql.org (Postfix) with ESMTP id 9698E9FB34B for ; Wed, 24 Oct 2007 11:53:48 -0300 (ADT) Received: from dilbert (dilbert.druid.net [207.35.13.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smaug.vex.net (Postfix) with ESMTP id E965A17304; Wed, 24 Oct 2007 10:53:44 -0400 (EDT) Date: Wed, 24 Oct 2007 10:53:43 -0400 From: "D'Arcy J.M. Cain" To: Nis =?ISO-8859-1?Q?J=F8rgensen?= Cc: pgsql-sql@postgresql.org, Paul Lambert , Tom Lane Subject: Re: Quick question re foreign keys. Message-Id: <20071024105343.582fb4e0.darcy@druid.net> In-Reply-To: <471EF78E.8050503@superlativ.dk> References: <471EA7D5.9040403@autoledgers.com.au> <21715.1193193880@sss.pgh.pa.us> <471EB55F.5050600@autoledgers.com.au> <20071024012705.5f253946.darcy@druid.net> <471EF78E.8050503@superlativ.dk> X-Mailer: Sylpheed 2.4.5 (GTK+ 2.12.0; i386--netbsdelf) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/109 X-Sequence-Number: 29481 On Wed, 24 Oct 2007 09:43:10 +0200 Nis J=F8rgensen wrote: > Well, I have a couple of times had the "need" to have a primary > key/uniqueness constraint with one column nullable (indicating "Not > Applicable"). The "problem" is that we have only one NULL, which for > comparison purposes is interpreted as "Not Known". Of course. Happens all the time. However, UNIQUE and PRIMARY are not the same thing. PRIMARY implies that the column uniquely and definitively identifies the row. If you have NULLs in the column than it does not meet the criteria. Here are the rules for primary key taken from http://articles.techrepublic.com.com/5100-22-1045050.html. - The primary key must uniquely identify each record. - A record?s primary-key value can?t be null. - The primary key-value must exist when the record is created. - The primary key must remain stable?you can?t change the primary-key fiel= d(s).=20 - The primary key must be compact and contain the fewest possible attribut= es.=20 - The primary-key value can?t be changed. --=20 D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.