Re: Commit and Exception Block - Mailing list pgsql-admin

From Tom Lane
Subject Re: Commit and Exception Block
Date
Msg-id 231422.1633705396@sss.pgh.pa.us
Whole thread Raw
In response to RE: Commit and Exception Block  (<soumik.bhattacharjee@kpn.com>)
List pgsql-admin
<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
catchis 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



pgsql-admin by date:

Previous
From:
Date:
Subject: RE: Commit and Exception Block
Next
From: Tim
Date:
Subject: Logical Replication Sync - Issue with Table Bloat