Subject: How do Exception, do nothing and carry on

From: Shaozhong SHI <[email-masked]>
Date: Thu, 6 Jul 2023 22:47:12 +0100

The function in the following block code may fail.

How to make it to carry on by ignoring exception?

Something like Python's try catch.

for i in (select distinct id from id_table)
  loop
         raise notice '%', i;
           insert into my_table(id, last, arr, count) SELECT i, * from
my_function(i) f(last int, arr int[], count int);
           commit;

  end loop;

---

From: "David G. Johnston" <[email-masked]>
Date: Thu, 6 Jul 2023 14:54:46 -0700

> my_function(i) f(last int, arr int[], count int);

Create a new function that traps [1] the failure and throws it away, then
call that function instead.

[1]
https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

David J.