Abort state on duplicated PKey in transactions - Mailing list pgsql-general

From Haroldo Stenger
Subject Abort state on duplicated PKey in transactions
Date
Msg-id 3B993C49.AE50BF8A@adinet.com.uy
Whole thread Raw
Responses Re: Abort state on duplicated PKey in transactions
List pgsql-general
Hi dear people,

I'm not sure if this is for general or for hackers, but let's start here
;-)

We are building a RAD tool (GeneXus) support, for PostgreSQL.

A problem which arose, is that within a transaction, if one inserts on a
table and the PK restriction is violated, the transaction aborts and
leaves itself in abort state. One has to END the transaction and start
a new one. This is a problem, in large transactions, where lots of
things have been done to the database, and an insertion is to be done,
which may yield an error just because the PK already existed. The whole
transaction should have to be redone if the insertion failed. A
solution, could be to query for the existance of the PK, just before the
insertion. But there is a little span between the test and the
insertion, where another insertion from another transaction could void
the existance test. Any clever ideas on how to solve this? Using
triggers maybe? Other solutions?

I'm aware that savepoints and nested transactions will be implemented in
future versions, but how to solve the problem before that starts
working?

Thanks

Regards,
Haroldo.

pgsql-general by date:

Previous
From: Andrew Sullivan
Date:
Subject: moving char() to varchar()
Next
From: "Thomas T. Thai"
Date:
Subject: Re: Idea: jobs.postgresql.org