Re: An easy question about creating a primary key

Stephan Szabo <sszabo@megazone23.bigpanda.com>

From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Ligia Pimentel <lmpimentel@yahoo.com>
Cc: <pgsql-sql@postgresql.org>
Date: 2001-12-03T19:16:14Z
Lists: pgsql-hackers, pgsql-sql
On Thu, 29 Nov 2001, Ligia Pimentel wrote:

> Hello.
>
> I'm using postgres 7.1. I have an easy question...
>
> 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?

I believe that's correct for 7.1 at least.  You can rename tables using
ALTER TABLE (alter table <table> rename to <newtable>).  If the column(s)
are marked not null already, you may be able to just get away with
creating a unique index on the column(s) named "<table>_pkey"