Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fB3JKJm16258 for ; Mon, 3 Dec 2001 14:20:19 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.7) with HTTP id 519076; Mon, 03 Dec 2001 11:20:07 -0800 From: "Josh Berkus" Subject: Re: An easy question about creating a primary key To: "Ligia Pimentel" , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.4.7 Date: Mon, 03 Dec 2001 11:20:07 -0800 Message-ID: In-Reply-To: <9u6gco$7fb$1@news.tht.net> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200112/30 X-Sequence-Number: 5853 Ligia, > I want to create a primary key constraint on an existing table. The > documentation says I can't . Please confirm. If this is true... How > can I > rename the existing table so I can create the new one and copy the > data? FYI, this question is more appropriate for the NOVICE list. You would use the same method that you use to drop and recreate the table for other reasons: CREATE TABLE tablea_temp AS SELECT * FROM tablea; DROP tablea; CREATE tablea ( primary_key SERIAL ... ); INSERT INTO tablea (column list) SELECT (column list) FROM tablea_temp; And don't forget to re-build your indexes! -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco