From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: Christophe Pettus <xof@thebuild.com>
Cc: Ravi Krishna <s_ravikrishna@aol.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP
Date: Tue, 18 Oct 2022 23:55:28 +0200
Message-ID: <811cd41fda48a12fe2c430e03dbf0f7fd57d49d2.camel@cybertec.at> (raw)
In-Reply-To: <2746245.1666128817@sss.pgh.pa.us>
References: <353091661.109766.1666124045054.ref@mail.yahoo.com>
<353091661.109766.1666124045054@mail.yahoo.com>
<72BEC008-DC6C-4D80-80A6-E1634CFFA656@thebuild.com>
<E05E818F-1CF6-40E2-A66A-8EB119AAB819@yugabyte.com>
<2746245.1666128817@sss.pgh.pa.us>
On Tue, 2022-10-18 at 17:33 -0400, Tom Lane wrote:
> Bryn Llewellyn <bryn@yugabyte.com> writes:
> > xof@thebuild.com wrote:
> > > You can commit in a loop, but not in BEGIN / END block that has an exception handler: that creates a subtransaction for the duration of the BEGIN / END.
>
> > This surprised me when I first started to use PG (after all those years
> > with ORCL).
>
> Really? BEGIN with an exception block is a subtransaction because it's
> defined to roll back to the database state as of the start of the block
> if an exception occurs. COMMIT in the middle fundamentally conflicts
> with that, I should think. Does Oracle interpret that differently?
Looks like Oracle doesn't care much about that:
SQL> CREATE TABLE mytab (id integer CHECK (id > 0));
Table created.
SQL> CREATE PROCEDURE committest IS
2 BEGIN
3 INSERT INTO mytab VALUES (42);
4 COMMIT;
5 INSERT INTO mytab VALUES (-42);
6 EXCEPTION
7 WHEN OTHERS THEN
8 NULL;
9 END;
10 /
Procedure created.
SQL> CALL committest();
Call completed.
SQL> SELECT * FROM mytab;
ID
----------
42
I looks like Oracle allows you to randomly interfere with its transaction handling.
If you run commit and then enter an exception handler, it simply doesn't rollback.
Yours,
Laurenz Albe
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: laurenz.albe@cybertec.at, tgl@sss.pgh.pa.us, bryn@yugabyte.com, xof@thebuild.com, s_ravikrishna@aol.com
Subject: Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP
In-Reply-To: <811cd41fda48a12fe2c430e03dbf0f7fd57d49d2.camel@cybertec.at>
References: <353091661.109766.1666124045054.ref@mail.yahoo.com> <353091661.109766.1666124045054@mail.yahoo.com> <72BEC008-DC6C-4D80-80A6-E1634CFFA656@thebuild.com> <E05E818F-1CF6-40E2-A66A-8EB119AAB819@yugabyte.com> <2746245.1666128817@sss.pgh.pa.us> <811cd41fda48a12fe2c430e03dbf0f7fd57d49d2.camel@cybertec.at>
* 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