On Wed, Apr 21, 2004 at 12:58:56 +0530, [EMAIL PROTECTED] wrote: > > The code looks like: > > update tempxitag set qty = qty + nqty where > ccod = cccod > GET DIAGNOSTICS nFound = ROW_COUNT; > If nFound = 0 then > insert into tempxitag( ccod, qty) > values (cccod, nqty ); > End if;
You still can get errors if two transactions try to refer to the same nonexistant record at the same time. Postgres doesn't do predicate locking so the update won't lock the to be inserted row and both transactions may see the record as not existing and both try to do an insert. Updating, checking the count and then trying an insert if the count was 0 and retrying if the insert fails may be a better approach than locking the table. However, since this is an existing application it may be hard to make this complicated of a change. If there is flexibility in how the task gets done, switching to something based on sequences is probably the way to go. ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly