Re: Concurrency Questions

From: cnliou <cnliou_at_eurosport.com>
Date: 25 Jul 2002 22:22:02 -0700
Message-ID: <eaa50a08.0207252122.3976fd6d_at_posting.google.com>


Thank you very much! Lauri,

The solution you provided is so far the best one I think. The only problem with it is that the database (postgresql) will abort the transaction when trying to insert a record with duplicate key value.

I wonder how other people tackle this problem which I think it being inevitable.

Regards,

CN

> You could try to "shoot first and ask questions later" like this:
>
> BEGIN TRANSACTION;
> INSERT INTO inventory VALUES (NewItemId,NewItemQty);
> IF <duplicate error> THEN
> UPDATE inventory SET qty=NewItemQty WHERE ItemId=NewItemId;
> SELECT qty FROM inventory where ItemId=NewItemId;
> END TRANSACTION;
Received on Fri Jul 26 2002 - 07:22:02 CEST

Original text of this message