From: Tom Lane <tgl@sss.pgh.pa.us>
To: FabrÃzio de Royes Mello <fabrizio@timbira.com.br>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: PegoraroF10 <marcos@f10.com.br>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Problem with trigger makes Detail record be invalid
Date: Thu, 19 Apr 2018 15:21:42 -0400
Message-ID: <2795.1524165702@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPfkCSCSU28WEjLEH99hdVr+TwScTxN7NAMFVycmjsy49jXAmg@mail.gmail.com>
References: <1524160534707-0.post@n3.nabble.com>
<7cb5806e-7371-5c19-1c7b-b8ac556bdfb5@aklaver.com>
<24449.1524164237@sss.pgh.pa.us>
<CAPfkCSCSU28WEjLEH99hdVr+TwScTxN7NAMFVycmjsy49jXAmg@mail.gmail.com>
=?UTF-8?Q?Fabr=C3=ADzio_de_Royes_Mello?= <fabrizio@timbira.com.br> writes:
> 2018-04-19 15:57 GMT-03:00 Tom Lane <tgl@sss.pgh.pa.us>:
>> (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.)
> We don't have it properly documented... at the time I answered this
> question on pt-br stackoverflow I noticed the lack o documentation and
> unfortunately I completely forgot to propose a small patch for it.
It strikes me that there are basically two things a trigger could do to
break FK consistency:
1. Turn an FK-commanded update into a no-op by returning NULL.
2. Change the content of the FK-related columns during an FK-commanded
update.
Both of these apply only to BEFORE ROW triggers, of course.
It might not be unreasonable or unduly expensive to throw an error for
case #1. I don't think I want to get into the expense of checking
for case #2, but covering case #1 would be enough to catch all of the
reports of this type of problem that I can remember.
IIRC, you can also break FK consistency with poorly-thought-out rules,
but given that rules are close-to-deprecated, I'm not very concerned
about sanding down rough edges in that case.
(But if you feel like writing a documentation patch, please do, because
we'd not be likely to back-patch a behavioral change like this even
if we get around to making it.)
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, fabrizio@timbira.com.br, adrian.klaver@aklaver.com, marcos@f10.com.br
Subject: Re: Problem with trigger makes Detail record be invalid
In-Reply-To: <2795.1524165702@sss.pgh.pa.us>
References: <1524160534707-0.post@n3.nabble.com> <7cb5806e-7371-5c19-1c7b-b8ac556bdfb5@aklaver.com> <24449.1524164237@sss.pgh.pa.us> <CAPfkCSCSU28WEjLEH99hdVr+TwScTxN7NAMFVycmjsy49jXAmg@mail.gmail.com> <2795.1524165702@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox