Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 972E0B5DBD8 for ; Wed, 7 Sep 2011 12:45:33 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 56855-01 for ; Wed, 7 Sep 2011 15:45:27 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vsmtp1.jaring.my (vsmtp1.jaring.my [192.228.250.213]) by mail.postgresql.org (Postfix) with ESMTP id AF909B5D80A for ; Wed, 7 Sep 2011 12:45:26 -0300 (ADT) DKIM-Signature: v=1; a=rsa-sha256; d=pop.jaring.my; s=mail; c=relaxed/simple; q=dns/txt; i=@pop.jaring.my; t=1315410606; x=1346946606; h=From:Sender:Reply-To:Subject:Date:To:Cc:Mime-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FF01G2D2p7MQTra6WOO4EFoSk5+pPCh7SSn5w4e//C4=; b=Oa5XPxOanMbrgPyOrMqLtu4T3RUTSJVuUGlvvXHtNHR+EUbHepFboq/9oJrF6xcT 5UWfiNhJ91pRTtsgGEVTcQaZEBIVYaucdxrB9tGCGL2UGYqcC3ViTAyPpC1KdEbk Gbr/l7XGyBXNmQUpiZxkGkusI5p4NubX1Jyg2LrLTMU=; X-AuditID: c0e4fad5-b7b97ae000001094-6c-4e6792ad1a41 Received: from core.localhost. ( [60.50.247.155]) by vsmtp1.jaring.my (JARING SMTP READY) with SMTP id 6F.C3.04244.DA2976E4; Wed, 7 Sep 2011 23:50:06 +0800 (MYT) X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Wed, 07 Sep 2011 23:45:11 +0800 To: Merlin Moncure From: Lincoln Yeoh Subject: Re: conditional insert Cc: jhondius@rem.nl,Pau Marc =?iso-8859-1?Q?Mu=F1oz?= Torres , pgsql-general@postgresql.org In-Reply-To: References: <4E64A79E.7030503@compulab.co.il> <4E64AC45.6030704@rem.nl> <20110906190548.433E8B5DBD1@mail.postgresql.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRmVeSWpSXmKPExsViY/R9tu66Sel+BscOcFg8/StscafzI6PF 1cZ37BbT725lc2Dx2DnrLrvHhX3T2D1Oti1iDmCO4rJJSc3JLEst0rdL4Mrof3SfseAyZ8W/ CUcYGxgvsXcxcnJICJhIbDq2nRHCFpO4cG89WxcjF4eQwBJGiSc7brF2MXIAJQwlti9gAalh EVCVuLN+J1hYREBdovNwHEiYTUBDYvWt62wgtrCApsTcea/ARjILFEt8WrySGaScUyBEYuFC D5CwkEADi8Su49wgYV4BQYm/O4RBTGYBa4n1j7ImMPLOQkjMQkgsYGRaxShQVpxbUmCol5VY lJmXrpdbuYkRGDoHnvy6uoNxVYPKIUYBDkYlHt6JgWl+QqyJZcWVuYcYJTmYlER5wyak+wnx JeWnVGYkFmfEF5XmpBYfYpTgYFYS4e1qAcrxpiRWVqUW5cOkpDlYlMR577wHmiSQnliSmp2a WpBaBJOV4eBQkuA9AzJUsCg1PbUiLTOnBCHNxMEJMpwHaPgPkBre4oLE3OLMdIj8KUZdjo13 lhxnFGLJy89LlRLnnQtSJABSlFGaBzcHFvOvGMWB3hLmbQep4gGmC7hJr4CWMAEtOZSfCrKk JBEhJdXAuDLCSlD1asX8FHFhcevpAR2ynde2Lco3Oj8x2fuW6fst3kt4G+olp9z4r6gtZntL e2uls+C3iI2dmo8j7PY/eDd3dcJOL5v1K234v0UZ/zpp5zHL9F3eY7lrHXNzeCv/MBxnDVEP uPT+q+jM9R3vQhZ8rQiv1A3run/Y55Nd7mZWxyuWFSe2K7EUZyQaajEXFScCAP5VjxnUAgAA Message-Id: <20110907154526.AF909B5D80A@mail.postgresql.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/184 X-Sequence-Number: 179542 At 05:23 AM 9/7/2011, Merlin Moncure wrote: >On Tue, Sep 6, 2011 at 3:45 PM, Merlin Moncure wrote: > > > b) doesn't block reads if you lock in EXCLUSIVE mode. a) is the best > > way to go if you prefer to handle errors on the client and/or > > concurrency is important...c) otherwise. > >whoops! meant to say b) otherwise! As far as c) goes, that is >essentially an advisory lock for the purpose -- using advisory locks >in place of mvcc locks is pretty weak sauce -- they should be used >when what you are locking doesn't follow mvcc rules. > >merlin Don't you have to block SELECTs so that the SELECTs get serialized? Otherwise concurrent SELECTs can occur at the same time, find no existing rows, then "all" the inserts proceed and you get errors (or dupes). That's how Postgresql still works right? I haven't really been keeping up. From what I see this (UPSERT/MERGE) has been a common problem/query over the years but it's not in a Postgresql FAQ and many people seem to be using methods that don't actually work. Google shows that many are even recommending those methods to others. Postgresql might still get blamed for the resulting problems. Regards, Link.