Postgres unique index checking and atomic transactions

From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Postgres unique index checking and atomic transactions
Date: 2003-07-24 16:26:13
Message-ID: 871xwfrivu.fsf@stark.dyndns.tv
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


So I have to adjust a primary key by adding one to every existing record.
Obviously this isn't a routine operation, my data model isn't that messed up.
It's a one-time manual operation.

However when I tried to do the equivalent of:

update tab set pk = pk + 1

I got

ERROR: Cannot insert a duplicate key into unique index tab_pkey

Is that right? Obviously after completing the query there would be no
duplicate keys. Is this a case where I would need deferred constraints to
allow this? Even for immediate constraints shouldn't a single sql update be
able to go ahead as long as it leaves things in a consistent state?

--
greg

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Ayers 2003-07-24 16:31:15 Re: Limited varchar, unlimited varchar, or text?
Previous Message Cory 'G' Watson 2003-07-24 16:23:49 Re: optimum postgres server configuration