Re: MERGE vs REPLACE - Mailing list pgsql-hackers

From Josh Berkus
Subject Re: MERGE vs REPLACE
Date
Msg-id 200511111440.54848.josh@agliodbs.com
Whole thread Raw
In response to Re: MERGE vs REPLACE  (Jaime Casanova <systemguards@gmail.com>)
Responses Re: MERGE vs REPLACE
Re: MERGE vs REPLACE
Re: MERGE vs REPLACE
List pgsql-hackers
Jaime,

> why? seems that REPLACE only work if there are at least one row
> matching...

Scenario:

session1: REPLACE .... 1                            session2:  REPLACE ..... 1
session1: check to see that "1" exists .... no                 session2: check to see that "1" exists .... no
session1: INSERT 1                 session2: INSERT 1 .... ERROR

Get the picture?  The only way to avoid a race condition is to be able to 
do "predicate locking", that is to lock the table against any data write 
matching that predicate.

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco


pgsql-hackers by date:

Previous
From: Bryan White
Date:
Subject: Re: How to find a number of connections
Next
From: Rod Taylor
Date:
Subject: Re: MERGE vs REPLACE