X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id DBA0BD1F779 for ; Sun, 9 May 2004 00:55:10 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 78922-06 for ; Sun, 9 May 2004 00:54:50 -0300 (ADT) Received: from 216.155.88.75.dsl.surnet.cl (216.155.91.100.DSL.surnet.cl [216.155.91.100]) by svr1.postgresql.org (Postfix) with ESMTP id C598FD1D2B5 for ; Sun, 9 May 2004 00:54:49 -0300 (ADT) Received: by 216.155.88.75.dsl.surnet.cl (Postfix, from userid 500) id 4A71813503; Sat, 8 May 2004 23:54:05 -0400 (CLT) Date: Sat, 8 May 2004 23:54:05 -0400 From: Alvaro Herrera To: Christopher Kings-Lynne Cc: Bruce Momjian , elein , PostgreSQL-development Subject: Re: Adding MERGE to the TODO list (resend with subject) Message-ID: <20040509035405.GA917@dcc.uchile.cl> References: <200405082246.i48MkTQ29755@candle.pha.pa.us> <409D8E48.3070805@familyhealth.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <409D8E48.3070805@familyhealth.com.au> User-Agent: Mutt/1.5.5.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=2.6 tagged_above=0.0 required=5.0 tests=RCVD_IN_DYNABLOCK, RCVD_IN_SORBS X-Spam-Level: ** X-Archive-Number: 200405/437 X-Sequence-Number: 53515 On Sun, May 09, 2004 at 09:50:00AM +0800, Christopher Kings-Lynne wrote: > >What does the MERGE command do? I have never heard of it, so I doubt > >someone is working on it. > > It is basically the SQL standard version of MySQL's REPLACE syntax. It > does an update-else-insert set. However, the trick is that it uses some > sort of next key locking to ensure that it cannot fail. Something that > is impossible to do in PostgreSQL at the moment. Nested transactions > will help, however. I intend to release locks on subtransaction abort, so if the update fails there's room for another transaction to insert the key (which I understand should fail?). I guess there's a different locking mechanism needed; I believe nested transactions will not be enough. -- Alvaro Herrera () "The first of April is the day we remember what we are the other 364 days of the year" (Mark Twain)