diff options
Diffstat (limited to 'doc/src/sgml/html/trigger-datachanges.html')
-rw-r--r-- | doc/src/sgml/html/trigger-datachanges.html | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/doc/src/sgml/html/trigger-datachanges.html b/doc/src/sgml/html/trigger-datachanges.html new file mode 100644 index 0000000..08a9de1 --- /dev/null +++ b/doc/src/sgml/html/trigger-datachanges.html @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>38.2. Visibility of Data Changes</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="trigger-definition.html" title="38.1. Overview of Trigger Behavior" /><link rel="next" href="trigger-interface.html" title="38.3. Writing Trigger Functions in C" /></head><body id="docContent" class="container-fluid col-10"><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">38.2. Visibility of Data Changes</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="trigger-definition.html" title="38.1. Overview of Trigger Behavior">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="triggers.html" title="Chapter 38. Triggers">Up</a></td><th width="60%" align="center">Chapter 38. Triggers</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 13.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="trigger-interface.html" title="38.3. Writing Trigger Functions in C">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="TRIGGER-DATACHANGES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">38.2. Visibility of Data Changes</h2></div></div></div><p> + If you execute SQL commands in your trigger function, and these + commands access the table that the trigger is for, then + you need to be aware of the data visibility rules, because they determine + whether these SQL commands will see the data change that the trigger + is fired for. Briefly: + + </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p> + Statement-level triggers follow simple visibility rules: none of + the changes made by a statement are visible to statement-level + <code class="literal">BEFORE</code> triggers, whereas all + modifications are visible to statement-level <code class="literal">AFTER</code> + triggers. + </p></li><li class="listitem"><p> + The data change (insertion, update, or deletion) causing the + trigger to fire is naturally <span class="emphasis"><em>not</em></span> visible + to SQL commands executed in a row-level <code class="literal">BEFORE</code> trigger, + because it hasn't happened yet. + </p></li><li class="listitem"><p> + However, SQL commands executed in a row-level <code class="literal">BEFORE</code> + trigger <span class="emphasis"><em>will</em></span> see the effects of data + changes for rows previously processed in the same outer + command. This requires caution, since the ordering of these + change events is not in general predictable; a SQL command that + affects multiple rows can visit the rows in any order. + </p></li><li class="listitem"><p> + Similarly, a row-level <code class="literal">INSTEAD OF</code> trigger will see the + effects of data changes made by previous firings of <code class="literal">INSTEAD + OF</code> triggers in the same outer command. + </p></li><li class="listitem"><p> + When a row-level <code class="literal">AFTER</code> trigger is fired, all data + changes made + by the outer command are already complete, and are visible to + the invoked trigger function. + </p></li></ul></div><p> + </p><p> + If your trigger function is written in any of the standard procedural + languages, then the above statements apply only if the function is + declared <code class="literal">VOLATILE</code>. Functions that are declared + <code class="literal">STABLE</code> or <code class="literal">IMMUTABLE</code> will not see changes made by + the calling command in any case. + </p><p> + Further information about data visibility rules can be found in + <a class="xref" href="spi-visibility.html" title="46.5. Visibility of Data Changes">Section 46.5</a>. The example in <a class="xref" href="trigger-example.html" title="38.4. A Complete Trigger Example">Section 38.4</a> contains a demonstration of these rules. + </p></div><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navfooter"><hr></hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="trigger-definition.html" title="38.1. Overview of Trigger Behavior">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="triggers.html" title="Chapter 38. Triggers">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="trigger-interface.html" title="38.3. Writing Trigger Functions in C">Next</a></td></tr><tr><td width="40%" align="left" valign="top">38.1. Overview of Trigger Behavior </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 13.4 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 38.3. Writing Trigger Functions in C</td></tr></table></div></body></html>
\ No newline at end of file |