Re: update record with two-column primary key

From: Lew <lew(at)lwsc(dot)ehost-services(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: update record with two-column primary key
Date: 2007-11-12 19:58:01
Message-ID: 4oSdncA2-KHULaXanZ2dnUVZ_ufinZ2d@comcast.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Almeida do Lago 2007-11-12 20:14:24 WAL segments size
Previous Message Lew 2007-11-12 19:54:37 Re: float to int