Re: Atomicity?

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org, Naz Gassiep <naz(at)mira(dot)net>
Subject: Re: Atomicity?
Date: 2006-08-28 20:12:49
Message-ID: A13B2A81-F9D4-4D8C-A155-B59F27716F93@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Aug 29, 2006, at 4:46 , Peter Eisentraut wrote:

> Naz Gassiep wrote:
>> conwatch=# UPDATE replies SET rgt = rgt + 2 WHERE postid = 18 AND rgt
>>> = 11;
>> ERROR: duplicate key violates unique constraint "replies_rgt_postid"
>
> This is a well-known deficiency in PostgreSQL. You will have to work
> around it somehow (by changing the query, the schema, or the index).

One such workaround is:

BEGIN;

UPDATE replies
SET rgt = -1 * (rgt + 2)
WHERE postid = 18
AND rgt >= 11;

UPDATE replies
SET rgt = -1 * rgt
WHERE rgt < 0;

COMMIT;

Michael Glaesemann
grzm seespotcode net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Naz Gassiep 2006-08-28 20:15:23 Re: Atomicity?
Previous Message Naz Gassiep 2006-08-28 20:00:29 Re: Atomicity?