Re: isn't "insert into where not exists" atomic?

From: Mage <mage(at)mage(dot)hu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: isn't "insert into where not exists" atomic?
Date: 2011-02-03 23:50:50
Message-ID: 4D4B3F5A.5090703@mage.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/03/2011 10:35 PM, pasman pasmański wrote:
> Your trigger is wrong. You try to insert the same row twice.
>
I assume you didn't try it. If active_at field is null then the trigger
does another insert instead of the original one. This avoids looping or
inserting twice.

The only mistake is that I tought the insert with select will be atomic
and I was wrong. So the trigger has concurrency problem in
multi-threaded environment. It runs flawlessly in single thread and it
does only a single insert.

Mage

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mage 2011-02-03 23:59:45 Re: isn't "insert into where not exists" atomic?
Previous Message Tom Lane 2011-02-03 22:43:56 Re: how to avoid repeating expensive computation in select