From: Adrian Klaver <adrian.klaver@aklaver.com>
To: andyterry <andrew.terry@centremaps.co.uk>
To: pgsql-general@postgresql.org
Subject: Re: commit within a procedure loop - cannot commite with subtransaction
Date: Mon, 21 Jan 2019 07:15:05 -0800
Message-ID: <7422ca90-de58-2bad-61e7-2365385829ca@aklaver.com> (raw)
In-Reply-To: <1548074591211-0.post@n3.nabble.com>
References: <1548074591211-0.post@n3.nabble.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, andrew.terry@centremaps.co.uk
Subject: Re: commit within a procedure loop - cannot commite with subtransaction
In-Reply-To: <7422ca90-de58-2bad-61e7-2365385829ca@aklaver.com>
References: <1548074591211-0.post@n3.nabble.com> <7422ca90-de58-2bad-61e7-2365385829ca@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox