Skip site navigation (1) Skip section navigation (2)

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:16:34
Message-ID: 4D65A362.6070800@intel.com (view raw or flat)
Thread:
Lists: pdxpug

On 02/23/2011 04:12 PM, Rich Shepard wrote:
> On Wed, 23 Feb 2011, Michael Ewan wrote:
>
>> 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.
>
> Michael,
>
>     Joe Celko doesn't like synthetic keys, either.
>
>     I suppose what I need to do is dump the table to a .sql file and make
> changes there. If I drop the table I lose all the hours of work getting data
> in there. :-(

Yes that would be a good idea, and was implied in any suggestion of 
dropping tables.  ;-)
Just be advised, pg_dump dumps to a copy from stdin: format with tab 
delimiters.

In response to

Responses

pdxpug by date

Next:From: Tim BruceDate: 2011-02-24 00:21:21
Subject: Re: Changing the Primary Key Column
Previous:From: Rich ShepardDate: 2011-02-24 00:12:12
Subject: Re: Changing the Primary Key Column

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group