Re: How do Exception, do nothing and carry on

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: How do Exception, do nothing and carry on
Date: 2023-07-06 21:54:46
Message-ID: CAKFQuwaaStSXsa0ZbBAxUujY02iUgCTJF=X3m0kCbPq=Lk+gLw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thursday, July 6, 2023, Shaozhong SHI <shishaozhong(at)gmail(dot)com> wrote:

> 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;
>

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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Shaozhong SHI 2023-07-08 15:30:31 How to remove duplicates in an array and maintain the order?
Previous Message Shaozhong SHI 2023-07-06 21:47:12 How do Exception, do nothing and carry on