Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fB42Trm41028 for ; Mon, 3 Dec 2001 21:29:54 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id fB42Toi21382; Mon, 3 Dec 2001 21:29:50 -0500 (EST) To: "Christopher Kings-Lynne" cc: "Ligia Pimentel" , "Hackers" Subject: Re: [SQL] An easy question about creating a primary key In-reply-to: References: Comments: In-reply-to "Christopher Kings-Lynne" message dated "Tue, 04 Dec 2001 10:23:19 +0800" Date: Mon, 03 Dec 2001 21:29:49 -0500 Message-ID: <21379.1007432989@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200112/71 X-Sequence-Number: 16219 "Christopher Kings-Lynne" writes: >> I think you've forgotten your own work, Chris. >> >> regression=# create table foo (bar int not null); >> CREATE >> regression=# alter table foo add primary key (bar); >> NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index >> 'foo_pkey' for table 'foo' >> CREATE >> regression=# > Bizarre. That patch was never committed. If you check > src/backend/commands/command.c and search for 'CONSTR_' you'll notice that > the CONSTR_UNIQUE function I implemented is there, but CONSTR_PRIMARY is > definitely not being handled. (I'm looking at the 7.2b2 source code) Hmm ... actually, I wonder whether that code in command.c isn't entirely dead code. I believe that as things stand, parser/analyze.c converts UNIQUE and PRIMARY constraints into CREATE INDEX statements; the constraint nodes themselves never make it past the parser. It looks to me like command.c only needs to handle CHECK constraints and foreign-key constraints, cf transformAlterTableStmt(). regards, tom lane