User-written triggers can modify or block the effects of SQL update and delete operations. That includes operations that are executed to implement foreign keys' referential integrity actions (such as ON UPDATE SET NULL or ON DELETE CASCADE). Therefore it's possible for a misdesigned trigger to result in a database state that violates the foreign key constraint. While this isn't great, the alternatives seem worse: in particular, refusing to fire triggers for such updates would break many valuable use-cases. We could also try to recheck the constraint after the action, but that'd roughly double the already-high cost of FK constraint enforcement, for no benefit in normal cases. So we've always considered that it's on the trigger programmer's head to avoid breaking RI actions. This was never documented anywhere, though. Add a para to the Triggers chapter to explain it. Laurenz Albe, David Johnston, Tom Lane Discussion: https://postgr.es/m/b81fe38fcc25a81be6e2e5b3fc1ff624130762fa.camel@cybertec.at
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.