Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-19 Thread Benedict Holland
This seems like a bad use of a stored procedure. Why wouldn't you spin up 40 clients with a table name and run it across 40 connections? But also, I don't like loops in stored procedures. Working with loops in a set based system hurts me but it's personal preference. Like, I could write this in py

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-19 Thread Thomas Kellerer
gogala.mla...@gmail.com schrieb am 19.10.2022 um 01:46: 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-transactions-t

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-19 Thread Bryn Llewellyn
It seems that I made a thread-discipline error when I asked a question that had nothing to do with the frequency, or the cost, of committing when I saw this reply (paraphrased for brevity here) from Christophe: > You [cannot] commit in [a] BEGIN / END [block statement] that has an > exception h

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-19 Thread Ron
On 10/19/22 08:06, Mladen Gogala wrote: [snip] Applications do this kind of thing all the time, very successfully; it was just that the loop was in the application rather than in the procedure. High commit rates happen all the time, and they don't break PostgreSQL.  For example, an IoT app

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-19 Thread Mladen Gogala
Comments in-line. On Tue, 2022-10-18 at 21:02 -0700, Christophe Pettus wrote: > > > > On Oct 18, 2022, at 19:18, gogala.mla...@gmail.com wrote: > > > > Commit within a loop is an extremely bad idea. > > This is an over-generalization.  There are many use-cases for this > (if there were not, pr

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Christophe Pettus
> On Oct 18, 2022, at 19:18, gogala.mla...@gmail.com wrote: > > Commit within a loop is an extremely bad idea. This is an over-generalization. There are many use-cases for this (if there were not, procedures wouldn't have been nearly as important a feature). For example, if you are processi

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread gogala . mladen
On Tue, 2022-10-18 at 14:31 -0700, Christophe Pettus wrote: > > Rather than have a loop inside the BEGIN / END, you could put the > BEGIN EXCEPTION END inside the loop, catch the error, store the > important parts of the exception in a variable, and then do the > COMMIT after the END statement but

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread gogala . mladen
On Tue, 2022-10-18 at 17:33 -0400, Tom Lane wrote: > Bryn Llewellyn writes: > > x...@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

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Laurenz Albe
On Tue, 2022-10-18 at 17:33 -0400, Tom Lane wrote: > Bryn Llewellyn writes: > > x...@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 surprise

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Christophe Pettus
> On Oct 18, 2022, at 14:15, Bryn Llewellyn wrote: > Could the limitation be lifted by making tractable internal implementation > changes? Or is it rooted in profoundly deep features of the > architecture—meaning that it could never be lifted? That is a very good question. One of the issues

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Tom Lane
Bryn Llewellyn writes: > x...@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).

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Christophe Pettus
> On Oct 18, 2022, at 14:29, Ravi Krishna 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. > > The reason I have to deal with error exception is that I want to ignore

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Ravi Krishna
> 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. The reason I have to deal with error exception is that I want to ignore failure on a table and move on to next table.  I thought I can tric

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Bryn Llewellyn
> x...@thebuild.com wrote: > >> s_ravikris...@aol.com wrote: >> >> I am getting error at COMMIT -> cannot commit while a subtransaction is >> active... > > 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

Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Christophe Pettus
> On Oct 18, 2022, at 13:14, Ravi Krishna wrote: > > I am getting error at COMMIT -> cannot commit while a subtransaction is > active. > Is commit not possible in a loop You can commit in a loop, but not in BEGIN / END block that has an exception handler: that creates a subtransaction for t

COMMIT IN STORED PROCEDURE WHILE IN A LOOP

2022-10-18 Thread Ravi Krishna
AWS Aurora based on PG 13 I am writing a sproc to copy a schema into another.  Here is the relevant portion of the code. Basically I want to commit after every table is created.  In big schemas with hundreds of table I do not want to run entire operation in one transaction. I am getting error a