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

Re: transaction

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: denis(at)coralindia(dot)com
Cc: "H(dot)J(dot) Sanders" <hjs(at)worldonline(dot)nl>, pgsql-sql(at)postgresql(dot)org
Subject: Re: transaction
Date: 2004-04-21 18:02:42
Message-ID: 20040421180242.GB30712@wolff.to (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-sql
On Wed, Apr 21, 2004 at 12:58:56 +0530,
  denis(at)coralindia(dot)com 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.

In response to

pgsql-sql by date

Next:From: HeflinDate: 2004-04-21 18:29:34
Subject: Join issue on a maximum value
Previous:From: Kemin ZhouDate: 2004-04-21 17:57:21
Subject: Server Side C programming Environment Set up

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