Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHWw9-0007eC-4b for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2023 21:54:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHWw8-0001RA-1T for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2023 21:54:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHWw7-0001R1-PJ for pgsql-sql@lists.postgresql.org; Thu, 06 Jul 2023 21:54:51 +0000 Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qHWw5-002QYm-AH for pgsql-sql@lists.postgresql.org; Thu, 06 Jul 2023 21:54:50 +0000 Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2b69dcf45faso19306011fa.0 for ; Thu, 06 Jul 2023 14:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688680488; x=1691272488; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Tk/IkQRKZF2FgHjCeFpRJEqjzMQRaufRuc8ljuUGPcI=; b=ogWvBzcGoEiP0mA32FVerPCKIxvmVAr12FnRfly3Ljc1N/avF4C2aVrCu2mu/Lv3DZ JXXAgb02Fsr6m01DyLEtJ1C+vQKub6k93deCzBDuhBa2Rg2iYHaZt04IYqS1Xt4btzV9 S/0NHSocWdIprOCHmuMRlaym7ufc/Ol2DSqIh2mDclb0myFDyJRjM6zzMTiEop2OWqjP dsXum1H8fcQ62OhjhpOBoTuUuSbJZKgBExppuVFHyDYPFZciSVtPAG5NzN//1D0dp7kY luja1LwLQeKtIokzay69RD+N5dhLjy+TIpFXnmUkT8YDeUAtKwKAanDh/q7Skm/ZWbnc V0fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688680488; x=1691272488; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Tk/IkQRKZF2FgHjCeFpRJEqjzMQRaufRuc8ljuUGPcI=; b=Sb4Z2OxL+cOA8UxTsGGtzmwHdO+77kHbxm2MaD44XK20Tr4gy6eNoZEmG8SqlKXIJC iTcJR42uXBWv57ZxqXysDWcPC/EV3529qTGeakKrGYsKSv3qA7BmmW0T2y7OYs65w9Sa rnJcGGRPhE2yewIF9vWd9l0+97O9QJIeLQ1YT2uwc5dkrMX4G1BiJPGvmYkKgMhesGV7 UO4anK03mKOteokPrubu5JoTqA+VkPaJ9+pLh1s12Sb3YYeW3ukWk+Dt/wMhGp1NRCfk 2q4YgXo9TtmkBsMO8mt/SlqRsy3ih6Jjy5ow1ICQ0G2mdG4KwC/z+RlEv7dGrtnNJQuA 3vpA== X-Gm-Message-State: ABy/qLYDRsSzEr4WNLZAVBhDBJUK5k4DdUy1N07/eM9Gyalvj04mGbyH m2iiyeZiHkX0VeRlhIjDimWtIlZK0POvUN7iplU= X-Google-Smtp-Source: APBJJlGPAjfudsnRpH3mXfN0QTx4Ug5OvOoPT88tTm01AGtU3KMYHaty/DjleMKd7y30/8nWLhyTfG23/1jeYr7sx9M= X-Received: by 2002:a2e:8050:0:b0:2b6:f1d5:619 with SMTP id p16-20020a2e8050000000b002b6f1d50619mr2248800ljg.14.1688680487292; Thu, 06 Jul 2023 14:54:47 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:640c:2cc4:b0:1d5:2732:4f73 with HTTP; Thu, 6 Jul 2023 14:54:46 -0700 (PDT) In-Reply-To: References: From: "David G. Johnston" Date: Thu, 6 Jul 2023 14:54:46 -0700 Message-ID: Subject: Re: How do Exception, do nothing and carry on To: Shaozhong SHI Cc: pgsql-sql Content-Type: multipart/alternative; boundary="00000000000095916705ffd8900b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000095916705ffd8900b Content-Type: text/plain; charset="UTF-8" On Thursday, July 6, 2023, Shaozhong SHI 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. --00000000000095916705ffd8900b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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 Pyt= hon's try catch.

for i in (select distinct id = from id_table)=C2=A0
=C2=A0 loop
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0raise notice '%', i;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0insert into my_table(id, last, arr, count) SELECT i, * from my= _function(i) f(last int, arr int[], count int);
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0commit;

=C2=A0 end loop;

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


David J.

--00000000000095916705ffd8900b--