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



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/

.



Relevant Pages

  • Re: Need input from Firebird users for a PostgreSQL vs Firebird comparison.
    ... The problem with using a domain is it's not out of the box support. ... There is TONS of new and cool features I could add from the upcoming ... PostgreSQL 8.3 but I wont do that because it's not a released version yet. ... When Firebird 2.1 is released I will update the comparison showing CLOB ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: {Spam?} RE: The funny thing about numbers is that theyre just
    ... Picking a PostgreSQL support vendor at random, I got a price of $2995 ... Well, yeah, but the guy I looked at for PostgreSQL support charged extra for any funny uses. ...
    (comp.databases.informix)
  • Re: How do I speed up this query ? (1.7M table entries)
    ... Filtering on the bounding square first allows us to use sargable ... > PostgreSQL, Oracle, and to some extent recent versions of MySQL each ... > have spatial index support using r-tree indexes. ... > I thought MS FoxPro was supposed to have some support for distance queries ...
    (microsoft.public.sqlserver)
  • Latest Apache13 with PHP5 crashes when PostgreSQL support is added
    ... time with php5 and extensions to support PostgreSQL 8.0.9. ... I have updated Apache to ... I am compiling php5-extensions with only pgsql support. ...
    (freebsd-questions)
  • Re: How do I speed up this query ? (1.7M table entries)
    ... I was surprised no one mentioned rtree/spatial indexes. ... PostgreSQL, Oracle, and to some extent recent versions of MySQL each ... have spatial index support using r-tree indexes. ... I thought MS FoxPro was supposed to have some support for distance queries ...
    (microsoft.public.sqlserver)