Re: Duplicate key insert question

From: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
To: Maksim Likharev <mlikharev(at)aurigin(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Duplicate key insert question
Date: 2003-07-02 01:10:57
Message-ID: 3F023121.7010209@mega-bucks.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2003-07-02 01:16:01 Re: PSQL NEWBIE - RUNTIME ERROR
Previous Message Maksim Likharev 2003-07-02 01:05:35 Re: Duplicate key insert question