public inbox for [email protected]  
help / color / mirror / Atom feed
How do Exception, do nothing and carry on
2+ messages / 2 participants
[nested] [flat]

* How do Exception, do nothing and carry on
@ 2023-07-06 21:47  Shaozhong SHI <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Shaozhong SHI @ 2023-07-06 21:47 UTC (permalink / raw)
  To: pgsql-sql <[email protected]>

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;


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: How do Exception, do nothing and carry on
@ 2023-07-06 21:54  David G. Johnston <[email protected]>
  parent: Shaozhong SHI <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2023-07-06 21:54 UTC (permalink / raw)
  To: Shaozhong SHI <[email protected]>; +Cc: pgsql-sql <[email protected]>

On Thursday, July 6, 2023, Shaozhong SHI <[email protected]> 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.


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-07-06 21:54 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 21:47 How do Exception, do nothing and carry on Shaozhong SHI <[email protected]>
2023-07-06 21:54 ` David G. Johnston <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox