Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1glbIF-0007JV-Tt for pgsql-general@arkaria.postgresql.org; Mon, 21 Jan 2019 15:15:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1glbIE-0007Jh-3X for pgsql-general@arkaria.postgresql.org; Mon, 21 Jan 2019 15:15:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1glbIC-0007JM-3z for pgsql-general@lists.postgresql.org; Mon, 21 Jan 2019 15:15:17 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1glbI8-0001DI-BS for pgsql-general@postgresql.org; Mon, 21 Jan 2019 15:15:14 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 862E628472; Mon, 21 Jan 2019 10:15:11 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 21 Jan 2019 10:15:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=h JPeBZUWXrfO9GmzrXwdzY2ahv3FxaP8gduLeb7ts/c=; b=JVer09t1Cs1wyXdKd mxzDpqVfnN4FBPu0m24qvQ9wsYqlD0nE9glv6OKnIjLl3PplAbll9OCH1jHIVr3d fskwC4NzmfbthzOtztOhW6FIy7md+soMAGu1DhhTiOkJdyKV2HN6YeOeLabiO5fX s4xYeyGwgJkg6TrB+n0bTRnNKXd2Qrh6kjeTa19uDc319fAAq6kbx8AVVSXdsZ5c wCzv90hRCdmQtf+QnNsdHfEdp4iYniAMuXSmLKNW1kKT4v1RHIRCsIe+ExbtVpXD iLQWoYXUbr5us8J5WbBDmRCg9Nj2GrQWO8xrroSr2Lkpb6Ekh3WtcscjvSKGlRWs pkLWw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=hJPeBZUWXrfO9GmzrXwdzY2ahv3FxaP8gduLeb7ts /c=; b=jSVyyLBxNeYvb0NVnJNXgLV/eM0knbRRM3he3J6iSahVxbJVrb6Lz7K3k Ljse7yJaLXxYUfTeDJTuSojoAGSZ9J0X2b4d0Ob8DFnKzJDBKg4N65aPqdXUjGYa uUZZZSFQQpRkbMdra32kHgahXXaVo4+g2w9iXBQaLzkJgVzwypT1CLv7nOExUGkN U1TGDMNUfmSsk8txd3rMoxtBWHvhafWcpZbLGTgeJ0VjLgZ7A6CxNuluOrFWtCvp S4JptYYmIgTHfkP2kJR056a3ZvfLksfvhtwDbvGI2WOIYq6Bkw41CXULv2AFb5pX T6LyoDs9F4L/GbieUbYVAqaRDux2A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrheeigdejgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpe etughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgv rhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdqrghrtghhihhvvgdroh hrghdpphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeejuddrvdduvddrudefgedrfeen ucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvh gvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 9DA21E4650; Mon, 21 Jan 2019 10:15:06 -0500 (EST) Subject: Re: commit within a procedure loop - cannot commite with subtransaction To: andyterry , pgsql-general@postgresql.org References: <1548074591211-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: <7422ca90-de58-2bad-61e7-2365385829ca@aklaver.com> Date: Mon, 21 Jan 2019 07:15:05 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <1548074591211-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/21/19 4:43 AM, andyterry wrote: > Hi, > > Using a procedure for the first time to run some processing for each row in > a table, generating output to a target table. The following works without > COMMIT the example below gives: > > INFO: Error Name:cannot commit while a subtransaction is active > INFO: Error State:2D000 > > Could someone point me in the right direction so i can understand why and > how i might rework my methodology? 1) This is Postgres 11, correct? 2) I have to believe the issue is the: PERFORM my_functions.processing_function(grd_geom); https://www.postgresql.org/docs/11/plpgsql-transactions.html "...But if the call stack is CALL proc1() → SELECT func2() → CALL proc3(), then the last procedure cannot do transaction control, because of the SELECT in between." 3) What is my_functions.processing_function() doing? > > > CREATE OR REPLACE PROCEDURE my_functions.first_procedure( > ) > LANGUAGE 'plpgsql' > > AS $BODY$ > > DECLARE > > grd_geom geometry(Polygon,27700); > grd_gid integer; > rec data.areas%rowtype; > > BEGIN > > DELETE FROM data.output; > DELETE FROM data.temp_output; > > FOR rec IN SELECT * FROM data.areas > LOOP > grd_geom := rec.geom; > grd_gid := rec.gid; > > PERFORM my_functions.processing_function(grd_geom); > DELETE FROM data.temp_output; > COMMIT; > END LOOP; > RETURN; > > > END; > > $BODY$; > > GRANT EXECUTE ON PROCEDURE my_functions.first_procedure() TO postgres; > GRANT EXECUTE ON PROCEDURE my_functions.first_procedure() TO PUBLIC; > > Thanks > > Andy > > > > -- > Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > > -- Adrian Klaver adrian.klaver@aklaver.com