Re: Changing the Primary Key Column

From: Brian Kurle <bk(at)travelingbits(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pdxpug(at)postgresql(dot)org
Subject: Re: Changing the Primary Key Column
Date: 2011-02-24 16:33:35
Message-ID: 6A13A14D-87DE-45D7-B8D7-45A7B07C3EC7@travelingbits.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pdxpug

As I stated, the documentation varies between releases, but seldom do features go away (it happens, but not very often). Thus, looking at the older notes can be very insightful and still valid.

As for adding the new primary key, it will be an add instead of a drop operation.

Perform a pg_dump on a simple table (even the one you have, but without dumping the table), and you'll even see the commands it would use to create the primary key to reconstruct it.

For one of my tables, after performing a pg_dump, I see the following:

ALTER TABLE ONLY action
ADD CONSTRAINT action_pkey PRIMARY KEY (transactionid);

You would do something similar.

http://www.postgresql.org/docs/9.0/static/sql-altertable.html

Brian Kurle
President
Traveling bits, Inc.
Cell: 503 961-2489
Fax: 503 640-3814

On Feb 24, 2011, at 8:03 AM, Rich Shepard wrote:

> On Thu, 24 Feb 2011, Brian Kurle wrote:
>
>> As was mentioned by Brent, you may have to look to see what the named
>> constraint is and use it.
>
> Brian,
>
> Got that, thanks.
>
>> Although the PostgreSQL documentation varies between releases, the
>> following appears to be more complete in it's explanations:
>>
>> http://www.postgresql.org/docs/8.0/static/sql-altertable.html
>
> I used the 9.1 page since I'm running 9.0.1.
>
> What remains is assigning a new primary key on the well_log column.
>
> Thanks,
>
> Rich
>

In response to

Responses

Browse pdxpug by date

  From Date Subject
Next Message Rich Shepard 2011-02-24 16:58:31 Re: Changing the Primary Key Column
Previous Message Rich Shepard 2011-02-24 15:59:15 Re: Changing the Primary Key Column