Re: Why didn't I get an error in the Exception block?

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Durumdara <durumdara(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why didn't I get an error in the Exception block?
Date: 2026-08-27 13:32:51
Message-ID: 063c61e68fdab32abdb53f2010b101ecc35e11e2.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2026-08-27 at 15:07 +0200, Durumdara wrote:
> When I start a Transaction from a Client and something fails, the PGSQL doesn't allow me to do anything else:
>
> > ERROR: current transaction is aborted, commands ignored until end of transaction block
>
> I wanted to check this situation so I created a demo in PGAdmin.
>
> do $$
> [...]
> begin
>   [...]
>    select * from fy__tx; -- This table does not exists
> exception  
>  when others then
> [...]
> end; $$;
>
> Why didn't I get this error in the Exception block?

Because a PL/pgSQL BEGIN ... EXCEPTION ... END block starts a subtransaction,
same as setting a savepoint. When you enter the exception handler, PL/pgSQL
performs a rollback to that savepoint, which undoes the error as well.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2026-08-27 14:58:11 Re: Why didn't I get an error in the Exception block?
Previous Message Durumdara 2026-08-27 13:07:46 Why didn't I get an error in the Exception block?