Re: Trigger Behavior in Transactions - Mailing list pgsql-general

From Bruce Momjian
Subject Re: Trigger Behavior in Transactions
Date
Msg-id 200512261606.jBQG6rv02710@candle.pha.pa.us
Whole thread Raw
In response to Trigger Behavior in Transactions  (Joshua Kramer <josh@bitbuckets.com>)
List pgsql-general
Joshua Kramer wrote:
>
> Greetings,
>
> Where in the documentation can I find information on the low-level
> behavior of triggers that fire as a result of insert/update statements
> inside of transactions?
>
> Do the triggers fire at the point the transaction is COMMITted?  Or as
> soon as the statements are encountered?  (If this is the case, how are
> rollbacks done - does the trigger also fire for the rollback?)
>
> I am creating a mechanism for updating PG databases remotely (from another
> PG database) for a magazine article I'm writing, and I need to figure out
> how to engineer the trigger mechamisms so they work properly.

These are complex questions.  Triggers fire at the end of the statement,
unless they are DEFERRRED (look that up).  I recommend you look up MVCC
to see how triggers fired on statement end are automatically rolled back
on abort, meaning we don't re-run the triggers on abort, the changes
the trigger made are ignored by other backends.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: newbie : setting access for users in a web enviroment
Next
From: Benjamin Arai
Date:
Subject: Restoring 64 to x86