Re: update record with two-column primary key - Mailing list pgsql-general

From Lew
Subject Re: update record with two-column primary key
Date
Msg-id 4oSdncA2-KHULaXanZ2dnUVZ_ufinZ2d@comcast.com
Whole thread Raw
In response to Re: update record with two-column primary key  ("Scott Marlowe" <scott.marlowe@gmail.com>)
List pgsql-general
Scott Marlowe wrote:
Charles Mortell wrote:
>> Using PG 8.0 on Windows, I have a table 'business_list' with a two column
>> primary key. It's a linking table and it's primary keys are the keys from
>> the two tables I am linking: item_id and business.
>> Should I be able to update one of those primary key fields?

Really it's a mistake to update a primary key.  A primary key by definition
identifies the row; changing it means to delete the row and insert a new one.

Updates are for when you've identified a specific row, that is, a specific
primary key.  That means that updates are only for dependent columns.

What you want to do is literally remove the old record and insert a new one.

The duplicate key violation is the purpose of having a primary key, after all.
  Otherwise you'd create two rows where you should only have one.

--
Lew

pgsql-general by date:

Previous
From: Abhijeet
Date:
Subject: regexp_replace() function in new version
Next
From: Lew
Date:
Subject: Re: float to int