Re: Adding another primary key to a populated table

From: Daniel Kunkel <DanielKunkel(at)BioWaves(dot)com>
To: andrew(at)supernews(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Adding another primary key to a populated table
Date: 2006-01-06 06:13:08
Message-ID: 1136527988.3321.80.camel@A64
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

It makes sense that I can't have more than 1 primary key.

Postgres was trying to create another primary key instead of modify the
existing primary key.

So...

As I understand it, a table does not always have to have a primary key
defined.

Would it work to first delete/drop the primary key, then recreate the
primary key on all 6 columns.

ALTER TABLE product_price DROP CONSTRAINT product_price_pkey;

I tried this, but it doesn't seem to work... If I look at the table
from pgAdmin, it is still there, reindexable, I can't add a new primary
key, etc. But if I try to run the above command twice, it says it's
already been removed.

--

Just for the record... the error message I got was:

ERROR: ALTER TABLE / PRIMARY KEY multiple primary keys for table
'product_price' are not allowed

On Fri, 2006-01-06 at 05:19 +0000, Andrew - Supernews wrote:
> On 2006-01-06, Daniel Kunkel <DanielKunkel(at)BioWaves(dot)com> wrote:
> > Hi
> >
> > I'm trying to add another primary key to a table populated with data and
> > a number of foreign key constraints.
>
> You can only have one primary key on a table.
>
> You can add additional unique constraints to get the same effect. (A
> primary key constraint is just a unique constraint that is also not null,
> and is the default target for REFERENCES constraints referring to the table -
> this last factor is why there can be only one...)
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Angshu Kar 2006-01-06 06:14:17 Re: Data loading from a flat file...
Previous Message Michael Fuhr 2006-01-06 05:48:46 Re: Data loading from a flat file...