Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DE5D2631F19 for ; Wed, 24 Jun 2009 05:37:55 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 38241-10 for ; Wed, 24 Jun 2009 05:37:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by mail.postgresql.org (Postfix) with ESMTP id B26B2631ADA for ; Wed, 24 Jun 2009 05:37:54 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MJNzK-0007XD-VJ for pgsql-sql@postgresql.org; Wed, 24 Jun 2009 08:37:50 +0000 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Jun 2009 08:37:50 +0000 Received: from hari.fuchs by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Jun 2009 08:37:50 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Re: Composite primary keys Date: Wed, 24 Jun 2009 10:37:37 +0200 Lines: 39 Message-ID: References: <20090623184412.GG27474@eddie> <24680.1245784517@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net X-Archive: encrypt User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:ebWB0KdiA8RF9wCWwSX0bEHmDtM= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200906/97 X-Sequence-Number: 32702 In article <24680.1245784517@sss.pgh.pa.us>, Tom Lane writes: > Joshua Tolley writes: >> Primary keys are NOT NULL and UNIQUE. You can't have null values in a primary >> key. > On reflection I think the OP's beef is that we complain about this: > regression=# create table t (f1 int null not null); > ERROR: conflicting NULL/NOT NULL declarations for column "f1" of table "t" > but not this: > regression=# create table t (f1 int null primary key); > NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t_pkey" for table "t" > CREATE TABLE > even though the implied NOT NULL is really a conflict. Yes, that's exactly what I found strange. > I think we could > fix that case if we cared to. However, since the NULL clause is > forgotten about after parsing, there isn't anything we could do to raise > a complaint about doing it in two steps: > regression=# create table t (f1 int null); > CREATE TABLE > regression=# alter table t add primary key(f1); > NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "t_pkey" for table "t" > ALTER TABLE > (barring remembering the NULL clause in the catalogs, which seems > entirely silly). I thought nullability is the default anyway, so indeed no need to remember it. My gripe was really the first case, where you contradict yourself in a single DDL statement.