pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: denis@coralindia.com
Cc: H.J. Sanders <hjs@worldonline.nl>
Cc: pgsql-sql@postgresql.org
Subject: Re: transaction
Date: Wed, 21 Apr 2004 13:02:42 -0500
Message-ID: <20040421180242.GB30712@wolff.to> (raw)
In-Reply-To: <003d01c42772$4fc3bf00$3332a8c0@DENIS>
References: <KIEBKBGIGGNDKKJJNKCFOELJCJAA.hjs@worldonline.nl>
	<20040421020010.GA19910@wolff.to>
	<003d01c42772$4fc3bf00$3332a8c0@DENIS>

On Wed, Apr 21, 2004 at 12:58:56 +0530,
  denis@coralindia.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.



view thread (5+ messages)

Message-ID: <20040421180242.GB30712@wolff.to>
Permalink:  ../20040421180242.GB30712@wolff.to/
Also on:    postgresql.org/message-id/20040421180242.GB30712@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, denis@coralindia.com, hjs@worldonline.nl
  Subject: Re: transaction
  In-Reply-To: <20040421180242.GB30712@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox