[prev in list] [next in list] [prev in thread] [next in thread]
List: postgresql-sql
Subject: Re: How do Exception, do nothing and carry on
From: "David G. Johnston" <david.g.johnston () gmail ! com>
Date: 2023-07-06 21:54:46
Message-ID: CAKFQuwaaStSXsa0ZbBAxUujY02iUgCTJF=X3m0kCbPq=Lk+gLw () mail ! gmail ! com
[Download RAW message or body]
On Thursday, July 6, 2023, Shaozhong SHI <shishaozhong@gmail.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.
[Attachment #3 (text/html)]
<br><br>On Thursday, July 6, 2023, Shaozhong SHI <<a \
href="mailto:shishaozhong@gmail.com">shishaozhong@gmail.com</a>> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>The function in the \
following block code may fail.</div><div><br></div><div>How to make it to carry on by \
ignoring exception?</div><div><br></div><div>Something like Python's try \
catch.</div><div><br></div><div>for i in (select distinct id from id_table) \
</div><div> loop</div><div> raise notice '%', \
i;</div><div><span style="white-space:normal"><span \
style="white-space:pre-wrap"> </span></span></div><div> <span \
style="white-space:pre-wrap"> </span> insert into my_table(id, last, arr, \
count) SELECT i, * from my_function(i) f(last int, arr int[], count int);</div><div> \
commit;</div><div><br></div><div> end \
loop;</div></div></div></blockquote><div><br></div><div>Create a new function that \
traps [1] the failure and throws it away, then call that function \
instead.</div><div><br></div><div>[1] <a \
href="https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL- \
ERROR-TRAPPING">https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING</a></div><div><br></div><div>David \
J.</div><div><br></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic