Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id A6C26632E16 for ; Sat, 3 Jul 2010 23:20:40 -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 12421-08 for ; Sun, 4 Jul 2010 02:20:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.4.227.11]) by mail.postgresql.org (Postfix) with ESMTP id 819E26325DA for ; Sat, 3 Jul 2010 23:20:33 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id 37150A20C; Sun, 4 Jul 2010 10:20:25 +0800 (WST) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 2AAB4AF325; Sun, 4 Jul 2010 10:19:12 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3xfNYJNF-Sf5; Sun, 4 Jul 2010 10:19:06 +0800 (WST) Received: from [10.1.1.6] (124-168-255-56.dyn.iinet.net.au [124.168.255.56]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id C52C6AF324; Sun, 4 Jul 2010 10:19:06 +0800 (WST) Message-ID: <4C2FEFE6.7010306@postnewspapers.com.au> Date: Sun, 04 Jul 2010 10:20:22 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: =?UTF-8?B?UmFkb3PFgmF3IFNtb2d1cmE=?= CC: pgsql-jdbc@postgresql.org Subject: Re: Unable to commit: transaction marked for rollback References: <20100701181528.GA97516@mr-paradox.net> <4C2CFDE1.1020308@mr-paradox.net> <4C2CBD620200002500032F49@gw.wicourts.gov> <201007031036.46492.mail@smogura.eu> In-Reply-To: <201007031036.46492.mail@smogura.eu> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-10 required=5 tests=BAYES_40=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/16 X-Sequence-Number: 20681 On 03/07/10 16:36, Radosław Smogura wrote: > I've looked at error from your example, because I didn't belived such > behavior. Unfortunatly it's true. Postgresql disallow to execute next > statement if error occured - this is realy bad approach, because error can be > from dupliacte keys etc. :( If you want to handle errors and continue, use a subtransaction with BEGIN SAVEPOINT and ROLLBACK TO SAVEPOINT. Most of the time it's a performance advantage - and perfectly suitable for apps - to avoid keeping a rollback point for each statement, and instead chuck the whole transaction away if something goes wrong. Most apps expect to retry the whole transaction if anything goes wrong anyway, since it's often hard to tell if the issue can be resolved by retrying just one (possibly altered) statement or not. It's also safer. If Pg allowed a transaction to continue after an INSERT failed, it'd end up committing an incomplete set of the requested changes and hoping that the user/app noticed. I don't like that - I'd much rather have to explicitly handle the issue, and otherwise have an error in a transaction be an error that aborts the transaction, not just the particular statement that caused the error. For bulk insertion, you're almost always better off copying the data into a temporary table, cleaning it up if necessary, then using INSERT INTO ... SELECT to insert it duplicate-free. I guess an optional mode that issued an implicit savepoint before each transaction and allowed "ROLLBACK TO LAST STATEMENT" would be nice, though, as a convenience to avoid all the savepoint management on the rare occasions when you do want statement-level rollback. -- Craig Ringer