Re: Working around spurious unique constraint errors due to SERIALIZABLE bug - Mailing list pgsql-general

From Florian Weimer
Subject Re: Working around spurious unique constraint errors due to SERIALIZABLE bug
Date
Msg-id 824ot7my9o.fsf@mid.bfk.de
Whole thread Raw
In response to Re: Working around spurious unique constraint errors due to SERIALIZABLE bug  ("Albe Laurenz" <laurenz.albe@wien.gv.at>)
List pgsql-general
* Albe Laurenz:

> The original question asked was "how can I tell an error that is caused
> by incomplete isolation from another error?"
>
> If you have a code segment like
>    SELECT COUNT(id) INTO i2 FROM a WHERE id = i;
>    IF i2 = 0 THEN
>       INSERT INTO a (id) VALUES (i);
>    END IF;
>
> Then you can be certain that any "unique_violation" thrown here must
> be a serialization problem (if the only unique contraint is on "id").

I want to put this into a library, so I'd like something foolproof.
Right now, user code sets a flag which basically says that the wrapper
should retry the transaction a few times if a unique_violation is
detected, but I'd like to get rid of that because it's one thing less
the programmer needs to worry about.

--
Florian Weimer                <fweimer@bfk.de>
BFK edv-consulting GmbH       http://www.bfk.de/
Kriegsstraße 100              tel: +49-721-96201-1
D-76133 Karlsruhe             fax: +49-721-96201-99

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Best practices for moving UTF8 databases
Next
From: Andreas Wenk
Date:
Subject: Re: Full text search in PostgreSQL 8.4