Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3ABB5475AFF for ; Wed, 7 Aug 2002 14:30:59 -0400 (EDT) Received: from sterling.betterhealthfoundation.net (user-112ugh2.biz.mindspring.com [66.47.66.34]) by postgresql.org (Postfix) with ESMTP id 6C338475ACF for ; Wed, 7 Aug 2002 14:30:58 -0400 (EDT) Received: from dinar ([192.168.1.12]) by sterling.betterhealthfoundation.net with Microsoft SMTPSVC(5.0.2195.4905); Wed, 7 Aug 2002 11:30:53 -0700 From: "Tom Haddon" To: "Christopher Kings-Lynne" , Subject: Re: ALTER TABLE follow up Date: Wed, 7 Aug 2002 11:30:53 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-OriginalArrivalTime: 07 Aug 2002 18:30:53.0292 (UTC) FILETIME=[8FE73AC0:01C23E40] X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/136 X-Sequence-Number: 8982 Hi Chris, Thanks for that. I have one final question (for the moment). How do I also alter the id column properties to reflect as below? DEFAULT nextval('agency_contact_info_id_key'::text) Is there an SQL query for this, or another manual "twiddle"? Thanks, Tom -----Original Message----- From: Christopher Kings-Lynne [mailto:chriskl@familyhealth.com.au] Sent: Tuesday, August 06, 2002 7:02 PM To: Tom Haddon; pgsql-sql@postgresql.org Subject: RE: [SQL] ALTER TABLE follow up Hi Tom, > A follow up to the ALTER TABLE question last week. I had asked why I was > getting an error message using the ALTER TABLE to add a PRIMARY > KEY, and was > told that this wasn't supported in 7.1.x. I've upgraded to 7.2.1 and now > when I use the following SQL: > > ALTER TABLE "agency_contact_info" ADD CONSTRAINT > "agency_contact_info_pkey" > PRIMARY KEY NOT NULL ("id"); I have no idea where you got that NOT NULL bit from - it's not in the manual. In fact Posgres 7.2 has no sql function for changing the null status of a column. You can manually twiddle the catalogs however - make SURE there's no NULL values in the column first: UPDATE pg_attribute SET attnotnull = true WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'agency_contact_info') AND attname = 'id'; Now just go: ALTER TABLE agency_contact_info ADD PRIMARY KEY (id): Chris