Handling db errors within transactions

From: Ed Loehr <eloehr(at)austin(dot)rr(dot)com>
To: pggeneral <pgsql-general(at)postgreSQL(dot)org>
Subject: Handling db errors within transactions
Date: 2001-08-20 20:32:30
Message-ID: 3B8173DE.9EB9DAEE@austin.rr.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have many DBI-based query sequences that look like this:

*** begin transaction ***
query #1: select ...
query #2: update ...
query #3: select ...
*** end transaction ***

If query #2 fails due to an exception (say, a duplicate key error), I can
identify that error **per query** via the DBI API, but then there appears
to be no possibility of even accessing the db again until/unless a
rollback is issued. All subsequent queries result in the famous line

NOTICE: current transaction is aborted, queries ignored until end of
transaction block

I know this is an issue that has been discussed previously and a true fix
involves a ton of work that nobody really wants to do; I'm looking more
for workaround ideas.

One obvious (and very ugly) solution is to wrap every db access with
logic to catch errors and additionally then issue a rollback and begin a
new transaction to enable additional queries. I like to find a cleaner
way to manage errors at a finer level of control granularity that still
enabled delegation of logic without major contortions.

Does anyone have any experience with a cleaner manner in which to handle
this issue?

Regards,
Ed Loehr

Browse pgsql-general by date

  From Date Subject
Next Message Evan Zane Macosko 2001-08-20 20:33:29 Re: Problems with UPDATE
Previous Message Evan Zane Macosko 2001-08-20 20:31:19 Re: Problems with UPDATE