Re: Duplicate key insert question - Mailing list pgsql-general

From Jean-Christian Imbeault
Subject Re: Duplicate key insert question
Date
Msg-id 3F023121.7010209@mega-bucks.co.jp
Whole thread Raw
In response to Re: Duplicate key insert question  ("Maksim Likharev" <mlikharev@aurigin.com>)
Responses Re: Duplicate key insert question  (Mike Mascari <mascarm@mascari.com>)
List pgsql-general
Maksim Likharev wrote:
>
> Finding if the duplicate value exists and inserting if not.

Ok, thanks but I think it is still vulnerable to a race condition.

> I do not know how that will work for PG, but in Microsoft SQL Server
> you can do following
> BEGIN TRANSACTION
> UPDATE [val] = [val]
>     WHERE ....
> INSERT ...
> COMMIT TRANSACTION
>
> so basically by updating specific row ( let say you have such row )
> in transaction, row/page lock will be held until end of transaction
> and concurrent UPDATE will wait until you are done.
> Kind of semaphore.

Why the UPDATE? And in postgres every query runs in it's own transaction
so no need for the explicit BEGIN / END block.

So can't see how your solution is any better than the previous one :)

Thanks,

Jean-Christian Imbeault


pgsql-general by date:

Previous
From: "Maksim Likharev"
Date:
Subject: Re: Duplicate key insert question
Next
From: Martijn van Oosterhout
Date:
Subject: Re: PSQL NEWBIE - RUNTIME ERROR