From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Durumdara <durumdara(at)gmail(dot)com> |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Am I in the same transaction block in complex PLPGSQL? |
Date: | 2022-03-11 15:01:12 |
Message-ID: | 830175.1647010872@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Durumdara <durumdara(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Durumdara | 2022-03-11 16:24:27 | Re: Am I in the same transaction block in complex PLPGSQL? |
Previous Message | George Woodring | 2022-03-11 14:48:45 | Re: foreign key on delete cascade order? |