X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D822E534C2 for ; Fri, 8 Apr 2005 15:59:38 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41097-07 for ; Fri, 8 Apr 2005 14:59:33 +0000 (GMT) Received: from smtp103.rog.mail.re2.yahoo.com (smtp103.rog.mail.re2.yahoo.com [206.190.36.81]) by svr1.postgresql.org (Postfix) with SMTP id 8274253217 for ; Fri, 8 Apr 2005 15:59:31 +0100 (BST) Received: from unknown (HELO phlogiston.dydns.org) (a.sullivan@rogers.com@216.75.167.195 with login) by smtp103.rog.mail.re2.yahoo.com with SMTP; 8 Apr 2005 14:59:30 -0000 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id C7AC53D2E; Fri, 8 Apr 2005 10:59:28 -0400 (EDT) Date: Fri, 8 Apr 2005 10:59:28 -0400 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: Question on triggers and plpgsql Message-ID: <20050408145928.GA27718@phlogiston.dyndns.org> References: <4255AA15.8000508@mochima.com> <14244.1112970986@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14244.1112970986@sss.pgh.pa.us> User-Agent: Mutt/1.5.6+20040907i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.051 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200504/90 X-Sequence-Number: 20983 On Fri, Apr 08, 2005 at 10:36:26AM -0400, Tom Lane wrote: > AFAICS the only way that you could get into a can't-roll-back situation > is if the trigger tries to propagate the update outside the database. > For instance, the proverbial trigger to send mail: once sent you can't > cancel it. But really this is dangerous even in an AFTER trigger --- > the transaction could still be rolled back after the AFTER trigger > fires. People who know more about this will no doubt correct me, but isn't such a case crying out for LISTEN/NOTIFY instead? That is, your trigger puts the mail content into a table of mails to be sent, and wakes up the mail-sender client with the NOTIFY; the NOTIFY and the commit to the mail-it table only happen in that case if the transaction commits. And since mail is async anyway, the extra few seconds shouldn't make any difference, right? A -- Andrew Sullivan | ajs@crankycanuck.ca The plural of anecdote is not data. --Roger Brinner