Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4C87D6345A3 for ; Thu, 23 Jul 2009 03:47:28 -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 37353-04 for ; Thu, 23 Jul 2009 03:47:17 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-px0-f202.google.com (mail-px0-f202.google.com [209.85.216.202]) by mail.postgresql.org (Postfix) with ESMTP id BA25A6337A6 for ; Thu, 23 Jul 2009 03:47:09 -0300 (ADT) Received: by pxi40 with SMTP id 40so492137pxi.15 for ; Wed, 22 Jul 2009 23:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=7E5RXyF4xs08fTSyA+GD6u0RDMGCRTO2AsVvxDKCHlc=; b=fyo76wEn/+HNksgpPEm0DfJiuFnvUmTX1sHVZFqRoEn/CPxwZgR/KE2GNFVc8rkWPK 4w6c38DC2QcJ5qmrSMf20zMTd6KjWICx4x5plKGXEbnL+MaazatCM2OjPWs0cc9ecXAV hUcpzHWbVyG9tMYdRY/kUE4HeYAWWKzFHyZq0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=XL04a4q6NI2IMGizgFNEn8zAmjfyedhSvaLs/HT8BBoUNu4E1kstvVVIQ9KHMKI1Rt c11FLm8EWo5xgexRsHseOJHTfHUPWlpAcMPAlLVj2cuwGMMu7fd10CTXeeVZ76GDa3xV 14aisj6vAS0kHzQQi+4s8NOZwe3L7gSxs+d/o= Received: by 10.114.103.15 with SMTP id a15mr2012844wac.184.1248331628591; Wed, 22 Jul 2009 23:47:08 -0700 (PDT) Received: from eddie (c-67-182-227-82.hsd1.ut.comcast.net [67.182.227.82]) by mx.google.com with ESMTPS id l30sm2911690waf.35.2009.07.22.23.47.06 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 22 Jul 2009 23:47:07 -0700 (PDT) Date: Thu, 23 Jul 2009 00:46:56 -0600 From: Joshua Tolley To: Glenn Maynard Cc: Richard Huxton , pgsql-sql@postgresql.org Subject: Re: Bit by "commands ignored until end of transaction block" again Message-ID: <20090723064656.GO25450@eddie> References: <4A67F5B6.4080409@archonet.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="WoqaC9TUMqqIOlla" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) 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/109 X-Sequence-Number: 32850 --WoqaC9TUMqqIOlla Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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: > >> =A0- Let me use SAVEPOINT outside of a transaction, > > > > You are never outside a transaction. All queries are executed within a > > transaction. >=20 > "Transaction block", then, if you insist. >=20 > > 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. >=20 > Savepoints can only be used inside transaction blocks. My function > has no idea whether it's being called inside a transaction block. >=20 > From inside a transaction block, my function would need to call > SAVEPOINT/RELEASE SAVEPOINT. >=20 > 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. = If you haven't explicitly opened one, PostgreSQL opens one for you before each statement, and issues a COMMIT afterwards (or a ROLLBACK, if your statement ran into an error). Statements within functions are always executed within = the same transaction, so you can issue SAVEPOINT commands anywhere in PL/pgSQL functions without problems, because you're always in a transaction. -- Joshua Tolley / eggyknap End Point Corporation http://www.endpoint.com --WoqaC9TUMqqIOlla Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkpoB2AACgkQRiRfCGf1UMONmACgqZcYDfK1i9swnXwb40PCQMRn 1dcAnjq/p96H4hZIcZmxTsunK+01I3ls =EMzx -----END PGP SIGNATURE----- --WoqaC9TUMqqIOlla--