Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 6B387B5DC1F for ; Thu, 8 Sep 2011 11:32:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 20741-07 for ; Thu, 8 Sep 2011 14:32:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vsmtp2.jaring.my (vsmtp2.jaring.my [192.228.250.215]) by mail.postgresql.org (Postfix) with ESMTP id 0C3AFB5DBCB for ; Thu, 8 Sep 2011 11:32:01 -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=1315492308; x=1347028308; 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=/MSgUWsPjzmOAJ/cs9UMmjv1JtSkI3cuq51ykjnlmOA=; b=RuaVCNE3XTUUSF1WBerR04dJzafTQaT/veD6lsjABFJ/N5gThZMFsmPAjSIQ84ul hlGY4YjlHD7FDFFqtl9cU/img6CdVVPTyCR7tMsTF11TrSiIU65twBC2tZTS6D/O /GSnJiwVOsrDzH/6o64ppubwbkJoJ7+qEDFEKKHN5cI=; X-AuditID: c0e4fad7-b7ce3ae000004d01-81-4e68d1d38ab3 Received: from core.localhost. ( [60.50.247.155]) by vsmtp2.jaring.my (JARING SMTP READY) with SMTP id 0C.2A.19713.4D1D86E4; Thu, 8 Sep 2011 22:31:48 +0800 (MYT) X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Thu, 08 Sep 2011 22:31:39 +0800 To: Andrew Sullivan ,pgsql-general@postgresql.org From: Lincoln Yeoh Subject: Re: conditional insert In-Reply-To: <20110907200454.GV35347@shinkuro.com> References: <4E64A79E.7030503@compulab.co.il> <4E64AC45.6030704@rem.nl> <20110906190548.433E8B5DBD1@mail.postgresql.org> <4e679195.12848e0a.019e.ffff918eSMTPIN_ADDED@mx.google.com> <20110907200454.GV35347@shinkuro.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRmVeSWpSXmKPExsViY/R9tu6Vixl+BhvnC1g86nvPYjH97lY2 ByaP6cemMnlc2DeNPYApissmJTUnsyy1SN8ugStj6ZVOxoLtXBUTjn5hamBcydHFyMEhIWAi 0baNvYuRE8gUk7hwbz1bFyMXh5DAEkaJD/+WM0PUGEpsX8ACUsMioCqx/mM/WFhEwE2ipysD JMwmoCGx+tZ1NhBbWEBTYu68V4wgJZwCRhJbzwZATHzGIvF11hOwVl4BQYm/O4RBTGYBa4n1 j7ImMPLMQkjMQkgsYGRaxShQVpxbUmCkl5VYlJmXrpdbuYkRGAYHnvy6voOx5aDaIUYBDkYl Ht6I6el+QqyJZcWVuYcYJTmYlER5c89n+AnxJeWnVGYkFmfEF5XmpBYfYpTgYFYS4Q0+AZTj TUmsrEotyodJSXOwKInz9l8ASgmkJ5akZqemFqQWwWRlODiUJHiDgOEuJFiUmp5akZaZU4KQ ZuLgBBnOAzScE6SGt7ggMbc4Mx0if4pRl2PjnSXHGYVY8vLzUqXEeb+CrQEpyijNg5sDi99X jOJAbwnzOoOM4gHGPtykV0BLmICWHMpPBVlSkoiQkmpgLDIRlvM/ajRhYaLt9PLYJp+5p56p rdxmv3tR7nqejGmCmatNRfQ4OiteNwm9PqHhFH5y2f+mT64bC29zL/p15/ea9qSNMc+39J5Q e/Iy+pXxI6c3ikdX692xl7W91/Pj8/kjbzIeqZ6weP133ny5mc4OaqYs8a/5k7/wiwu4zIiX N/7klu3xW4mlOCPRUIu5qDgRALYBhK66AgAA Message-Id: <20110908143203.0C3AFB5DBCB@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/228 X-Sequence-Number: 179586 At 04:04 AM 9/8/2011, Andrew Sullivan wrote: >On Wed, Sep 07, 2011 at 02:51:32PM -0500, Merlin Moncure wrote: > > > > @andrew s: going SERIALIZABLE doesn't help if you trying to eliminate > > cases that would push you into retrying the transaction. > >Well, no, of course. But why not catch the failure and retry? I >guess I just don't get the problem, since I hear people say this all >the time. (I mean, I've also seen places where 'upsert' would be >cool, but it doesn't seem trivial to do in a general way and you can >do this with catch-serialization-error-and-retry, I think?) Doesn't catching the failure and retrying mean writing more code? Need extra code: 1) to handle the savepoint. 2) to correctly distinguish between "retryable" errors and "nonretryable" errors. 3) to retry transactions. More code to debug, test, document and support :). In contrast, the "lock table, insert if row does not exist, update if it exists" and rollback everything if "stuff happens" seems simpler to do correctly. I personally prefer to leave as much code writing to others (e.g. those writing Postgresql, programming languages and libraries), because I assume they are much better at writing code than I am. Plus I usually don't have to document and support their code ;). Regards, Link.