Re: Changing the Primary Key Column

From: Michael Ewan <michael(dot)ewan(at)intel(dot)com>
To: pdxpug(at)postgresql(dot)org
Subject: Re: Changing the Primary Key Column
Date: 2011-02-24 00:06:48
Message-ID: 4D65A118.1020200@intel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pdxpug

On 02/23/2011 03:34 PM, Rich Shepard wrote:
> This, too, is new to me. The first table column is a contrived key that is
> no longer needed as a unique row identifier. The second column should
> replace the first as the primary key. The ALTER TABLE command can add a
> primary key to a column, but I don't see how to remove that constraint from
> column1, add it to column2, so I can drop column1.
>

Maybe someone else has a better answer but in my experience you have to
drop the table to change the PK. You can add/drop other indexes or FK.
How about leaving the synthetic PK and adding an extra index for your
other key. Doing that also gets you away from any duplicate primary key
errors. Although Josh Berkus will probably slap me silly for ever
suggesting a synthetic key.

In response to

Responses

Browse pdxpug by date

  From Date Subject
Next Message Rich Shepard 2011-02-24 00:12:12 Re: Changing the Primary Key Column
Previous Message Rich Shepard 2011-02-23 23:34:52 Changing the Primary Key Column