Re: serialization errors - Mailing list pgsql-general

From Tom Lane
Subject Re: serialization errors
Date
Msg-id 20701.1043776040@sss.pgh.pa.us
Whole thread Raw
In response to serialization errors  (Ryan VanderBijl <rvbijl-pgsql@vanderbijlfamily.com>)
Responses Re: serialization errors
List pgsql-general
Ryan VanderBijl <rvbijl-pgsql@vanderbijlfamily.com> writes:
> There are many reasons that the INSERT statement could fail (e.g. syntax,
> database connection dropped, conflicting concurrent update, unique constraint).

An INSERT statement can *never* fail because of a concurrent conflicting
update, because it isn't an update.  Any INSERT is, logically speaking,
creating a unique new entity (row) in the database; there is no conflict
against other insertions, unless by way of violation of a unique constraint.

> If I receive the legal error "duplicate key" error, how am I supposed to
> detect if that error is due to a concurrent update, or because of some
> other error elsewhere?

What difference does it make if the other guy got there ten microseconds
or ten years earlier?  He inserted before you did.  Whether it's
"concurrent" or not shouldn't matter that I can see.  Perhaps more to
the point, there is no reason to expect that a duplicate-key failure
will succeed if you retry the same insertion.

            regards, tom lane

pgsql-general by date:

Previous
From: Tilo Schwarz
Date:
Subject: Q: Rename constraint
Next
From: Gordan Bobic
Date:
Subject: How do I unsubscribe?