Re: Replaceing records - Mailing list pgsql-general

From Shridhar Daithankar
Subject Re: Replaceing records
Date
Msg-id 3F5761BB.23467.77CB3C@localhost
Whole thread Raw
In response to Re: Replaceing records  (Csaba Nagy <nagy@ecircle-ag.com>)
List pgsql-general
On 4 Sep 2003 at 12:17, Csaba Nagy wrote:

> This problem would be easily solved if the current transaction would not
> be automatically rolled back on the failed insert. Given this, it would
> be as easy as trying the insert, and if fails, do the update.

That violates definition of a transaction. You need nested transaction which
aren't there..

You can use a sequence to insert. If next value of sequence is more than value
you have, probably somebody has inserted the value. Then modify it.

Or do a select for update. If it returns the error, there is no record. So
insert, otherwise update.

It might still fail though but chances will be much less.

HTH

Bye
 Shridhar

--
Air Force Inertia Axiom:    Consistency is always easier to defend than
correctness.


pgsql-general by date:

Previous
From: Peter Childs
Date:
Subject: Re: Optimizer picks an ineffient plan
Next
From: "Bjorn T Johansen"
Date:
Subject: Re: Tomcat Connection Pool?