Re: Am I in the same transaction block in complex PLPGSQL? - Mailing list pgsql-general

From Tom Lane
Subject Re: Am I in the same transaction block in complex PLPGSQL?
Date
Msg-id 830175.1647010872@sss.pgh.pa.us
Whole thread Raw
In response to Am I in the same transaction block in complex PLPGSQL?  (Durumdara <durumdara@gmail.com>)
Responses Re: Am I in the same transaction block in complex PLPGSQL?
List pgsql-general
Durumdara <durumdara@gmail.com> writes:
> In autocommit mode, when I start a simple update or select, it is one
> transaction, so if something fails, the whole modification is rolled back
> (there is no "half update", or "only first record updated").
> What will happen with complex statements, like PLPGSQL stored procedure, or
> trigger?

It's one transaction unless you take steps to make it something else.
In plpgsql, you can make "sub transactions" with BEGIN/EXCEPTION blocks
(an exception rolls back only side-effects that happened since BEGIN).
Or, if it's a procedure not a function, you can explicitly COMMIT
what's been done so far, and then your next action starts a new
transaction.  But without such measures, all actions executed by
a function are part of the same transaction as the calling statement.

            regards, tom lane



pgsql-general by date:

Previous
From: George Woodring
Date:
Subject: Re: foreign key on delete cascade order?
Next
From: Durumdara
Date:
Subject: Re: Am I in the same transaction block in complex PLPGSQL?