Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id AD074633444 for ; Fri, 24 Jul 2009 06:43:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 36583-08 for ; Fri, 24 Jul 2009 09:43:49 +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 A59E463269E for ; Fri, 24 Jul 2009 06:43:48 -0300 (ADT) Received: from [10.0.0.5] (tillium.localnet [10.0.0.5]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 5CF7C1E0454; Fri, 24 Jul 2009 17:43:43 +0800 (WST) Subject: Re: Bit by "commands ignored until end of transaction block" again From: Craig Ringer To: Chris Cc: Joshua Tolley , Glenn Maynard , Richard Huxton , pgsql-sql@postgresql.org In-Reply-To: <4A680C03.6040701@gmail.com> References: <4A67F5B6.4080409@archonet.com> <20090723064656.GO25450@eddie> <4A680C03.6040701@gmail.com> Content-Type: text/plain Date: Fri, 24 Jul 2009 17:43:42 +0800 Message-Id: <1248428622.1101.188.camel@tillium.localnet> 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 tagged_above=-10 required=5 tests=none X-Spam-Level: X-Archive-Number: 200907/121 X-Sequence-Number: 32862 On Thu, 2009-07-23 at 17:06 +1000, Chris wrote: > Joshua Tolley wrote: > > On Thu, Jul 23, 2009 at 02:04:53AM -0400, Glenn Maynard wrote: > >> On Thu, Jul 23, 2009 at 1:31 AM, Richard Huxton wrote: > >>>> - Let me use SAVEPOINT outside of a transaction, > >>> You are never outside a transaction. All queries are executed within a > >>> transaction. > >> "Transaction block", then, if you insist. > >> > >>> I think this is the root of your problem - all queries are within a > >>> transaction so either: > >>> 1. You have a transaction that wraps a single statement. If you get an error > >>> then only that statement was affected. > >>> 2. You have an explicit BEGIN...COMMIT transaction which could use a > >>> savepoint. > >> Savepoints can only be used inside transaction blocks. My function > >> has no idea whether it's being called inside a transaction block. > >> > >> From inside a transaction block, my function would need to call > >> SAVEPOINT/RELEASE SAVEPOINT. > >> > >> If it's not in a transaction block, it needs to call BEGIN/COMMIT > >> instead. SAVEPOINT will fail with "SAVEPOINT can only be used in > >> transaction blocks". > > > > Have you tried this? I expect if you give it a shot, you'll find you don't > > actually have this problem. Really, everything is always in a transaction. [snip] > You haven't explicitly started a transaction, therefore savepoints won't > work. True. However, he's talking about code within a PL/PgSQL function. To a PL/PgSQL function there is NO difference between: begin; select my_function(); commit; and a standalone: select my_function(); in both cases the statement executes in a transaction, and in both cases individual statements within the function are within the same transaction. That's why any function can EXCEPTION blocks, etc, which rely on savepoints. -- Craig Ringer