I would like to track the progress of a for loop in a postgresql function. For that, I insert every 100th value of the loop variable into a table done
. However, when I query done
i see nothing until the function stops executing. Is there a way to change that?
Asked
Active
Viewed 81 times
0

nokiddn
- 251
- 2
- 6
-
I am afraid that if your loop runs inside a transaction then you can't change that. If it's not multi-user system with transactions, you could do COMMIT every 100th value however thiss may break your loop when many people are running it concurrently. – Andrew Jan 30 '18 at 16:06
-
oops. I did not expect I will dupe it all along. @nokiddn - I can explain you if you don't find linked answer enough – Vao Tsun Jan 30 '18 at 16:53
-
Thanks, dblink seems like an overkill in my situation. I am just trying to figure out, if the tables I'm updating in the function only get updated at the end of execution. I guess the answer is yes. – nokiddn Jan 30 '18 at 17:25
-
1yes - you start transaction and run statements, among them functions, and see the result in SAME transaction only - from running function - yes, but you can check "middle result" from other session/transaction. so workaround with dblinks is the easiest way to deceive db here... – Vao Tsun Jan 30 '18 at 20:46