From: Tom Lane <tgl@sss.pgh.pa.us>
To: soumik.bhattacharjee@kpn.com
Cc: pgsql-admin@lists.postgresql.org
Subject: Re: Commit and Exception Block
Date: Fri, 08 Oct 2021 11:03:16 -0400
Message-ID: <231422.1633705396@sss.pgh.pa.us> (raw)
In-Reply-To: <a7dacaf0474d48deaf82fe9ad6289ed9@kpn.com>
References: <05e4b1ba5e4741e08f63c113b5dd5ef7@kpn.com>
<a7dacaf0474d48deaf82fe9ad6289ed9@kpn.com>
<soumik.bhattacharjee@kpn.com> writes:
> I have a procedure that may encounter an exception. I want to have an exception handling block where exception is to catch is any FK violations.
> Could you please suggest where it's getting missed as part of a transaction.
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, soumik.bhattacharjee@kpn.com, pgsql-admin@lists.postgresql.org
Subject: Re: Commit and Exception Block
In-Reply-To: <231422.1633705396@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox