Re: Trigger transaction isolation

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Dirk Lattermann <dlatt(at)alqualonde(dot)de>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Trigger transaction isolation
Date: 2020-09-01 15:02:01
Message-ID: 54137.1598972521@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> writes:
> As I understand it a trigger function runs in its own transaction so the
> rules from below apply:
> https://www.postgresql.org/docs/12/transaction-iso.html

No, a trigger is part of the calling transaction. There's nothing special
about it other than the condition causing the call; visibility rules are
the same as for any other function. So the answer to the OP's question
depends on the transaction's isolation level and (for typical
PLs) on whether the function is VOLATILE or not.

serializable -> the transaction's initial snapshot is used throughout

non serializable, volatile function -> each statement in the function
takes a fresh snapshot

non serializable, non-volatile function -> the function uses a single
snapshot. For a non-deferred trigger, I think it shares the snapshot
used by the triggering query. Not sure about exactly when the snapshot
is taken for a deferred trigger.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2020-09-01 16:05:02 Re: Is it possible to set end-of-data marker for COPY statement.
Previous Message Adrian Klaver 2020-09-01 14:41:52 Re: Trigger transaction isolation