Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2fb7560

Browse files
committed
Doc: document that triggers can break referential integrity.
User-written triggers can modify or block the effects of SQL updateand delete operations. That includes operations that are executedto implement foreign keys' referential integrity actions (such asON UPDATE SET NULL or ON DELETE CASCADE). Therefore it's possiblefor a misdesigned trigger to result in a database state that violatesthe foreign key constraint.While this isn't great, the alternatives seem worse: in particular,refusing to fire triggers for such updates would break many valuableuse-cases. We could also try to recheck the constraint after theaction, but that'd roughly double the already-high cost of FKconstraint enforcement, for no benefit in normal cases. So we'vealways considered that it's on the trigger programmer's head toavoid breaking RI actions. This was never documented anywhere,though. Add a para to the Triggers chapter to explain it.Laurenz Albe, David Johnston, Tom LaneDiscussion:https://postgr.es/m/b81fe38fcc25a81be6e2e5b3fc1ff624130762fa.camel@cybertec.at
1 parent482e108 commit2fb7560

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎doc/src/sgml/trigger.sgml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,17 @@
354354
to avoid infinite recursion in such scenarios.
355355
</para>
356356

357+
<para>
358+
If a foreign key constraint specifies referential actions (that
359+
is, cascading updates or deletes), those actions are performed via
360+
ordinary SQL update or delete commands on the referencing table.
361+
In particular, any triggers that exist on the referencing table
362+
will be fired for those changes. If such a trigger modifies or
363+
blocks the effect of one of these commands, the end result could
364+
be to break referential integrity. It is the trigger programmer's
365+
responsibility to avoid that.
366+
</para>
367+
357368
<para>
358369
<indexterm>
359370
<primary>trigger</primary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp