BUG #12330: ACID is broken for unique constraints

From: nikita(dot)y(dot)volkov(at)mail(dot)ru
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #12330: ACID is broken for unique constraints
Date: 2014-12-24 14:01:53
Message-ID: 20141224140153.11501.49752@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

The following bug has been logged on the website:

Bug reference: 12330
Logged by: Nikita Volkov
Email address: nikita(dot)y(dot)volkov(at)mail(dot)ru
PostgreSQL version: 9.2.4
Operating system: OSX 10.8.2
Description:

Executing concurrent transactions inserting the same value of a unique key
fails with the "duplicate key" error under code "23505" instead of any of
transaction conflict errors with a "40***" code.

E.g., having the following table:

CREATE TABLE "song_artist" (
"song_id" INT8 NOT NULL,
"artist_id" INT8 NOT NULL,
PRIMARY KEY ("song_id", "artist_id")
);

Even trying to protect from this with a select, won't help to get away from
the error, because at the beginning of the transaction the key does not
exist yet.

BEGIN ISOLATION LEVEL SERIALIZABLE READ WRITE;
INSERT INTO song_artist (song_id, artist_id)
SELECT 1, 2
WHERE NOT EXISTS (SELECT * FROM song_artist WHERE song_id=1 AND
artist_id=2);
COMMIT;

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff Janes 2014-12-24 15:05:11 Re: BUG #12326: I think maybe postgresql has a problem about timezone.
Previous Message 284466130 2014-12-24 13:21:07 BUG #12328: can't install the postgresql

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2014-12-24 14:08:50 Re: replicating DROP commands across servers
Previous Message Fujii Masao 2014-12-24 13:51:44 Re: Moving RestoreBlockImage from xlogreader.c to xlogutils.c