develooper Front page | perl.dbi.users | Postings from August 2006

Re: peer review: recipe for solving SELECT/INSERT/UPDATE race condition

Thread Previous
From:
Mark Stosberg
Date:
August 21, 2006 18:16
Subject:
Re: peer review: recipe for solving SELECT/INSERT/UPDATE race condition
Message ID:
44EA681B.20701@summersault.com
Stuart Cooper wrote:
>> Sometimes it's desirable to first to a SELECT to see if a row exists,
>> and then INSERT if it doesn't already, or UPDATE if it does.
> 
> MySQL's got a really handy 'REPLACE INTO' for just this circumstance,
> some have suggested that PostgreSQL should support this in future.

The SQL 2003 Standard has a really handy "MERGE INTO" for just this 
circumstance, too. You can search for "MERGE INTO" on this page to read 
about it:
http://www.varlena.com/GeneralBits/73.php

I hope both PostgreSQL and MySQL support this in the future.

> Your solution looks good.

Thanks.

       Mark

-- 
http://mark.stosberg.com/


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About