Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 7128063283F for ; Sun, 26 Jul 2009 21:01:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 30590-06 for ; Mon, 27 Jul 2009 00:00:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id C544A632A5B for ; Sun, 26 Jul 2009 21:00:35 -0300 (ADT) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 5FCCE1E044F; Mon, 27 Jul 2009 08:00:31 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id y3P7vBbFqb8n; Mon, 27 Jul 2009 08:00:29 +0800 (WST) Received: from [10.1.1.2] (124-169-239-69.dyn.iinet.net.au [124.169.239.69]) (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 89B181E0449; Mon, 27 Jul 2009 08:00:29 +0800 (WST) Subject: Re: Bit by "commands ignored until end of transaction block" again From: Craig Ringer To: Science Cc: pgsql-sql@postgresql.org In-Reply-To: <4A6CE37B.9020709@misuse.org> References: <4A6CE37B.9020709@misuse.org> Content-Type: text/plain Date: Mon, 27 Jul 2009 08:00:28 +0800 Message-Id: <1248652828.2303.5.camel@ayaki> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.053 tagged_above=-10 required=5 tests=AWL=0.053 X-Spam-Level: X-Archive-Number: 200907/131 X-Sequence-Number: 32872 On Sun, 2009-07-26 at 19:15 -0400, Science wrote: > FWIW, the way the Rails ORM ActiveRecord (another fairly damaged ORM) > handles this is by allowing you to open any number of transaction > blocks, but only the outer transaction block commits (in Pg): > > Property.transaction { # SQL => 'BEGIN' > User.transaction { > Foo.transaction { > Foo.connection.execute('--some sql code') # SQL => '--some sql code' > } > } > } # SQL => 'COMMIT' What happens if, Foo.transaction does something that causes an error, though, or issues a rollback? It's not creating savepoints, so if Foo.transaction rolls back it throws out the work of User.transaction and Property.transaction too. Ugh. That design would be quite good _IF_ it used savepoints: Property.transaction { # SQL => 'BEGIN' User.transaction { # SQL => SAVEPOINT User Foo.transaction { # SQL => SAVEPOINT Foo Foo.connection.execute('--some sql code') # SQL => '--some sql code' } # SQL => RELEASE SAVEPOINT Foo } # SQL => RELEASE SAVEPOINT User } # SQL => 'COMMIT' ... so that inner transactions could ROLLBACK TO SAVEPOINT on error , and so that asking for a rollback would give you a ROLLBACK TO SAVEPOINT if the transaction is a subtransaction. -- Craig Ringer