Re: Problem with trigger makes Detail record be invalid - Mailing list pgsql-general

From Tom Lane
Subject Re: Problem with trigger makes Detail record be invalid
Date
Msg-id 24449.1524164237@sss.pgh.pa.us
Whole thread Raw
In response to Re: Problem with trigger makes Detail record be invalid  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Problem with trigger makes Detail record be invalid  (Fabrízio de Royes Mello <fabrizio@timbira.com.br>)
Re: Problem with trigger makes Detail record be invalid  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 04/19/2018 10:55 AM, PegoraroF10 wrote:
>> Is this a bug or it´s mine responsability to check that trigger result ?

> Without seeing exactly what the trigger function on Detail is doing that 
> is not answerable.

I think the OP is complaining because his misimplemented trigger can break
the consistency of the foreign key constraint.  That is not a bug, it's
an intentional design decision: triggers are lower-level than foreign key
enforcement queries, and fire during such queries.  It's easy to construct
examples where people would be very unhappy if this were not so, because
then FK-driven updates would not be seen by the table's triggers.  It does
mean that you have to be careful when writing a trigger.

(I'm not sure that this issue is adequately documented, though.
I'd have expected to find something about it in triggers.sgml and/or
create_trigger.sgml, but in a quick look neither of them mentions foreign
keys.)

            regards, tom lane


pgsql-general by date:

Previous
From: PegoraroF10
Date:
Subject: Re: Problem with trigger makes Detail record be invalid
Next
From: Adrian Klaver
Date:
Subject: Re: Problem with trigger makes Detail record be invalid