Re: Working around spurious unique constraint errors due to SERIALIZABLE bug

From: Florian Weimer <fweimer(at)bfk(dot)de>
To: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: "Craig Ringer *EXTERN*" <craig(at)postnewspapers(dot)com(dot)au>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Working around spurious unique constraint errors due to SERIALIZABLE bug
Date: 2009-07-20 10:42:11
Message-ID: 824ot7my9o.fsf@mid.bfk.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)bfk(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Wenk 2009-07-20 11:10:09 Re: Full text search in PostgreSQL 8.4
Previous Message Martijn van Oosterhout 2009-07-20 10:28:39 Re: Best practices for moving UTF8 databases