Re: Problem with stored procedure and nested transactions

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: p(dot)pierotti(at)mmbb(dot)it, pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with stored procedure and nested transactions
Date: 2018-11-03 08:48:09
Message-ID: 9b2b5575-7e28-832e-3559-7bfce974c525@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 30/10/2018 15:03, p(dot)pierotti(at)mmbb(dot)it wrote:
> I thought that the “BEGIN/END” block was used to create new transactions
> and that each of them could be managed individually.

In PL/pgSQL, BEGIN/END just create syntactic blocks, they don't manage
transactions.

COMMIT and ROLLBACK manage top-level transactions, but those cannot be
nested (since they are top-level).

In order to create a nested transaction structure, you need to use
subtransactions. In PL/pgSQL, you can use BEGIN/END blocks with an
exception clause to create subtransactions.

I'm not sure what your code is actually trying to do, but you might need
to reorganize it a bit.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2018-11-03 12:14:19 Re: backend crash on DELETE, reproducible locally
Previous Message Tom Lane 2018-11-03 03:56:58 Re: backend crash on DELETE, reproducible locally