Skip site navigation (1) Skip section navigation (2)

Re: JDBC squirrely transaction behavior??

From: Steve Wampler <swampler(at)noao(dot)edu>
To: postgres-interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: JDBC squirrely transaction behavior??
Date: 2000-06-05 15:37:44
Message-ID: 393BC948.43803086@noao.edu (view raw or flat)
Thread:
Lists: pgsql-interfaces
Peter Mount wrote:
> 
....
> 
> > This code will run for a number of insertions, then fail because the
> > select of the foo_id returns no records.  This should be impossible,
> > because either (1) the foo_id was just added to the foos table, or (2)
> > it had previously been added.  Either way, there should be a record
> > with a matching namefield.
> 
> I can see a problem here. Your first insert inserts foo_id, and fails if
> foo_id already exists. In your code, you ignore this which is fine outside
> a Transaction. However, because you are using a transaction, the
> transaction is now in a failed state, so everything else done in that
> transaction will be ignored.

Hmmm, that may cause me a problem in a similar situation - I want to
do an update whenever an insert fails.  Further, for performance reasons
the insertions are done in large transactions (thousands to tens of
thousands of inserts in each transaction).  Does the above comment mean
that this ("update after failed insert") won't work as I'd like because
it's inside a transaction?  Is there a way to force the state of the
transaction back to success after the failed insert, without losing the
insertions that have been made previously in the transaction [or those
that are made subsequently...]?

> The alternative is to but a connection.commit() after the insert, which
> may work in this case, but you have to think about the integrity of your
> tables.

This sounds like it would work in my case - does anyone see why it wouldn't
or have a more appropriate approach?  (Through JDBC, of course.)

Thanks!




--
Steve Wampler-  SOLIS Project, National Solar Observatory
swampler(at)noao(dot)edu

In response to

Responses

pgsql-interfaces by date

Next:From: Joachim AchtzehnterDate: 2000-06-05 16:26:36
Subject: Re: JDBC squirrely transaction behavior??
Previous:From: Dave PageDate: 2000-06-05 12:00:25
Subject: pgAdmin v7.0.1 Released

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group