Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 4B066634B06 for ; Tue, 23 Jun 2009 16:15:21 -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 74535-01 for ; Tue, 23 Jun 2009 16:15:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id D8A06634484 for ; Tue, 23 Jun 2009 16:15:19 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n5NJFHsV024681; Tue, 23 Jun 2009 15:15:17 -0400 (EDT) To: Joshua Tolley cc: Harald Fuchs , pgsql-sql@postgresql.org Subject: Re: Composite primary keys In-reply-to: <20090623184412.GG27474@eddie> References: <20090623184412.GG27474@eddie> Comments: In-reply-to Joshua Tolley message dated "Tue, 23 Jun 2009 12:44:12 -0600" Date: Tue, 23 Jun 2009 15:15:17 -0400 Message-ID: <24680.1245784517@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.091 tagged_above=0 required=5 tests=AWL=0.091 X-Spam-Level: X-Archive-Number: 200906/95 X-Sequence-Number: 32700 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. 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). So I'm not sure how interesting it is to complain about the single-command case. regards, tom lane