Re: Trigger behaviour not as stated

From: "Ian R(dot) Campbell" <ian(dot)campbell(at)thepathcentral(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, ian(at)thepathcentral(dot)com, pgsql-docs(at)postgresql(dot)org, Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Subject: Re: Trigger behaviour not as stated
Date: 2018-01-29 11:32:34
Message-ID: CAOC8YUdZ-J42bUz2SFXsQjnAiv5YfkDR5rupN0pGP=ZLY-wt8Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

The original confusion on this is answered in part by the following
statement (taken from the answer to my SO question):

"UPDATEs and DELETEs on the parent table will affect rows in the child
tables (if you don't specify ONLY), but triggers will only be fired by data
modifications directed directly against the table with the trigger on it "

This clearly explains that a trigger attached to a parent table will not
fire if the data being modified is in a child table.

The second part of the confusion is that INSERT is not considered to be a
row modification and will fire a BEFORE INSERT trigger on the parent table
even when the data goes into a child (whereas UPDATE and DELETE will not
fire a parent trigger).

My proposal (adapted from Tom's):

In contrast, row-level UPDATE and DELETE triggers are fired for individual
row change
events only on the table to which the trigger is attached. Therefore,
UPDATE and DELETE triggers on
a parent table will only fire when rows in the parent table are being
modified. Likewise,
UPDATE and DELETE triggers on a child table will only fire when rows in
the child table are being modified.
Note that INSERT statements do not follow these update rules, so
statements run on parent tables will
insert rows in child tables if the trigger function so directs.

The last line may need a bit of work, but I feel the text above it is clear.

Ian

On Mon, 29 Jan 2018 at 07:17 Bruce Momjian <bruce(at)momjian(dot)us> wrote:

> On Sun, Jan 28, 2018 at 06:12:01PM -0500, Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > Oh, I am sorry. I was focused on the first part of the sentence and
> > > didn't notice your change to the second part. How is this attachment?
> >
> > Seems same as your previous version?
>
> OK, new vesion that uses "explicitly named" in both modified doc lines.
>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
> EnterpriseDB http://enterprisedb.com
>
> + As you are, so once was I. As I am, so you will be. +
> + Ancient Roman grave inscription +
>

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2018-01-29 15:28:32 Re: Trigger behaviour not as stated
Previous Message Bruce Momjian 2018-01-28 23:17:19 Re: Trigger behaviour not as stated