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 1mYrPL-0004Tg-AD for pgsql-admin@arkaria.postgresql.org; Fri, 08 Oct 2021 15:03:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mYrPK-0001gU-03 for pgsql-admin@arkaria.postgresql.org; Fri, 08 Oct 2021 15:03:34 +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 1mYrPJ-0001gL-NI for pgsql-admin@lists.postgresql.org; Fri, 08 Oct 2021 15:03:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mYrPC-0004FW-H2 for pgsql-admin@lists.postgresql.org; Fri, 08 Oct 2021 15:03:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 198F3GmY231423; Fri, 8 Oct 2021 11:03:17 -0400 From: Tom Lane To: soumik.bhattacharjee@kpn.com cc: pgsql-admin@lists.postgresql.org Subject: Re: Commit and Exception Block In-reply-to: References: <05e4b1ba5e4741e08f63c113b5dd5ef7@kpn.com> Comments: In-reply-to message dated "Fri, 08 Oct 2021 08:00:34 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <231421.1633705396.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 08 Oct 2021 11:03:16 -0400 Message-ID: <231422.1633705396@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk writes: > I have a procedure that may encounter an exception. I want to have an ex= ception handling block where exception is to catch is any FK violations. > Could you please suggest where it's getting missed as part of a transact= ion. I think you're confused about the scope of the exception block. The syntax is BEGIN some code here that might throw an exception EXCEPTION some WHEN clauses here to catch exceptions from the covered code END You wrote: > begin > RAISE SQLSTATE 'MYERR'; > EXCEPTION > WHEN ... So this exception block can *only* trap errors arising from that one RAISE command, not anything earlier in the procedure. Seems unlikely that's what you wanted. regards, tom lane