Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okwIA-0005gH-E8 for pgsql-general@arkaria.postgresql.org; Tue, 18 Oct 2022 23:46:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1okwI8-0004xI-AK for pgsql-general@arkaria.postgresql.org; Tue, 18 Oct 2022 23:46:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okwI7-0004x9-SV for pgsql-general@lists.postgresql.org; Tue, 18 Oct 2022 23:46:35 +0000 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1okwI5-0007td-9p for pgsql-general@lists.postgresql.org; Tue, 18 Oct 2022 23:46:35 +0000 Received: by mail-qk1-x735.google.com with SMTP id z30so9724398qkz.13 for ; Tue, 18 Oct 2022 16:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:references:in-reply-to:date:cc:to:from :subject:message-id:from:to:cc:subject:date:message-id:reply-to; bh=z79xemhkiDocvoO/Wm+Sb67h0agrQIwBEp9Zcu9zmBI=; b=hGsXLKGZ4d7gu3QRIS7Ca0Qfc4mJlQQ7Z4TsozLcgXgt966l1h3jjb5/j5y2oUChXB hxYHXjRQqCjNFKk75l+1u/YEgNRKVF9sjyn7nMaLdrqeZBBU4cPWINGjbvj0THw56WTn mCNKjglgB/5vbFF83nhlbLhqPF2okmIHYQMO3nDZm7k8545/BbR2pzHcJJZp9Kqo9qtD YIJEV//ZIOyH3LIm5ZFPzx9F+i2zL8r38XWuSlQ3MpqXqTMtZkMNuiBJTdA6monvHsa5 /b1LVPgkBc+FOWcZj+fHhgncPbDZI6PCXO6kz5x4/YhnMfnxYOuIkP/IiQHBhNxEtrp7 zNpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:references:in-reply-to:date:cc:to:from :subject:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=z79xemhkiDocvoO/Wm+Sb67h0agrQIwBEp9Zcu9zmBI=; b=U72XIjHCOSoedgKpWyuZKtcCYT+0SnJuwLlGkqoGy06oQCRi0+bxCNhrE8BUn6QipF 12ik29OQ6+TUD7rZ84UFiALhLNp9+efP+ZkNr+lVzDqMYfbdHSOtGvVyh18hypbmtKLA 8Ek5cK14HG+vBCB2r0f6oaF7+zEzV/0xplqgbU4CCsd/xGdjER4GYTBX06TCiYhUIwUf 0aLEluy8XrA4YofA+s2V1Worn1OI08WE9f+5APCD8xl+nU8LuijGVBzxH+R4K2Fq57lU xIObrPmOZO+HQlcIODWtHPczF6zklMgau9ByW2D5yVdvqXClu42jxlh3FxjeKIOM1n7w CN0A== X-Gm-Message-State: ACrzQf15olS1+fgEGEB7jFm9FvRQT4Mrdi9+1kS7p4kp8hhWaIaV7oBG RYLrD4KUpiODIh7TVGyOHG0= X-Google-Smtp-Source: AMsMyM5rvEXl5+XFeMrbbd0csRHHUFZqmXTVKVf8fXPuk6nQfVTBhyXLAKiGmgJWfI+lHnGIlgLp2g== X-Received: by 2002:a05:620a:40c9:b0:6ed:562d:ee0 with SMTP id g9-20020a05620a40c900b006ed562d0ee0mr3756001qko.750.1666136791200; Tue, 18 Oct 2022 16:46:31 -0700 (PDT) Received: from [192.168.2.100] (pool-72-79-30-4.nwrknj.east.verizon.net. [72.79.30.4]) by smtp.gmail.com with ESMTPSA id v21-20020a05620a441500b006cbe3be300esm3604948qkp.12.2022.10.18.16.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 16:46:30 -0700 (PDT) Message-ID: Subject: Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP From: gogala.mladen@gmail.com To: Tom Lane , Bryn Llewellyn Cc: Christophe Pettus , Ravi Krishna , pgsql-general list Date: Tue, 18 Oct 2022 19:46:29 -0400 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> <2746245.1666128817@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="=-ofPr8ot0xXD9+U6I9gYr" User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-ofPr8ot0xXD9+U6I9gYr Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 2022-10-18 at 17:33 -0400, Tom Lane wrote: > Bryn Llewellyn writes: > > xof@thebuild.com=C2=A0wrote: > > > 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. >=20 > > This surprised me when I first started to use PG (after all those > > years > > with ORCL). >=20 > Really?=C2=A0 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.=C2=A0 COMMIT in the middle fundamentally conflict= s > with that, I should think.=C2=A0 Does Oracle interpret that differently? >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0reg= ards, tom lane >=20 >=20 Hi Tom, Yes, Oracle does interpret that differently. Bryn may correct me if I'm wrong, but Oracle creates an implicit save point when it encounters BEGIN. Exception handler doesn't necessarily roll things back. Oracle behavior is not standard and PgSQL adheres to SQL standard better than Oracle. However, being as pervasive as it is, Oracle is de facto =C2=A0standard. Also, Oracle has something called "autonomous transaction" which, in effect, means that a session can have two concurrent transactions open, which is also non-standard: https://docs.oracle.com/en/database/oracle/oracle-database/19/lnpls/AUTONOM= OUS_TRANSACTION-pragma.html#GUID-AD33D949-081B-4CD3-A240-C29773E908C3 Amazon, lead by Kevin Closson, the guy who has famously designed Oracle Exadata among other things, even came up with the recipe how to migrate it to Postgres: https://aws.amazon.com/blogs/database/migrating-oracle-autonomous-transacti= ons-to-postgresql/ I am a bit skeptical toward that recipe and I usually prefer programming solutions with opening another thread and sending a message. BTW, speaking of Kevin, he has also written pgio, which is a PostgreSQL version of his SLOB package. Kevin is the only retired Oracle ACE in existence. BTW, Bryn also used to be an Oracle ACE. Regards --=-ofPr8ot0xXD9+U6I9gYr Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
On Tue, 2022-10-18 at 17:33 -0400, Tom Lane w= rote:
Bryn Llewellyn <bryn@yugabyte.com> writes:
You can commit i= n 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 s= urprised me when I first started to use PG (after all those years
=
with ORCL).

Really?  BE= GIN 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 inter= pret that differently?

    = ;            &n= bsp;       regards, tom lane



Hi Tom,
<= div>Yes, Oracle does interpret that differently. Bryn may correct me if I'm= wrong, but Oracle creates an implicit save point when it encounters BEGIN.= Exception handler doesn't necessarily roll things back. Oracle behavior is= not standard and PgSQL adheres to SQL standard better than Oracle. However= , being as pervasive as it is, Oracle is de facto  standard.Also, Oracle has something called "autonomous transaction" which, in effec= t, means that a session can have two concurrent transactions open, which is= also non-standard:


Amazon, lead by Kevin Closson, the guy who has famously designed Oracle Ex= adata among other things, even came up with the recipe how to migrate it to= Postgres:


I am a bit skeptical toward that re= cipe and I usually prefer programming solutions with opening another thread= and sending a message. BTW, speaking of Kevin, he has also written pgio, w= hich is a PostgreSQL version of his SLOB package. Kevin is the only retired= Oracle ACE in existence. BTW, Bryn also used to be an Oracle ACE.
Regards
--=-ofPr8ot0xXD9+U6I9gYr--