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 1glZBJ-0006Nu-VO for pgsql-general@arkaria.postgresql.org; Mon, 21 Jan 2019 13:00:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1glZBI-0003V3-KI for pgsql-general@arkaria.postgresql.org; Mon, 21 Jan 2019 13:00:00 +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 1glYvA-000557-5i for pgsql-general@lists.postgresql.org; Mon, 21 Jan 2019 12:43:20 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1glYv2-0006HD-DV for pgsql-general@postgresql.org; Mon, 21 Jan 2019 12:43:18 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 3464611890520 for ; Mon, 21 Jan 2019 05:43:11 -0700 (MST) Date: Mon, 21 Jan 2019 05:43:11 -0700 (MST) From: andyterry To: pgsql-general@postgresql.org Message-ID: <1548074591211-0.post@n3.nabble.com> Subject: commit within a procedure loop - cannot commite with subtransaction MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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? 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