From: Josh Berkus <josh@agliodbs.com>
To: Ligia Pimentel <lmpimentel@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: An easy question about creating a primary key
Date: Mon, 03 Dec 2001 11:20:07 -0800
Message-ID: <web-519076@davinci.ethosmedia.com> (raw)
In-Reply-To: <9u6gco$7fb$1@news.tht.net>
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 ...
<snip>
);
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, lmpimentel@yahoo.com
Subject: Re: An easy question about creating a primary key
In-Reply-To: <web-519076@davinci.ethosmedia.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox