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