gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 line
5.0KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!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><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 12.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>
  3. If you execute SQL commands in your trigger function, and these
  4. commands access the table that the trigger is for, then
  5. you need to be aware of the data visibility rules, because they determine
  6. whether these SQL commands will see the data change that the trigger
  7. is fired for. Briefly:
  8. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  9. Statement-level triggers follow simple visibility rules: none of
  10. the changes made by a statement are visible to statement-level
  11. <code class="literal">BEFORE</code> triggers, whereas all
  12. modifications are visible to statement-level <code class="literal">AFTER</code>
  13. triggers.
  14. </p></li><li class="listitem"><p>
  15. The data change (insertion, update, or deletion) causing the
  16. trigger to fire is naturally <span class="emphasis"><em>not</em></span> visible
  17. to SQL commands executed in a row-level <code class="literal">BEFORE</code> trigger,
  18. because it hasn't happened yet.
  19. </p></li><li class="listitem"><p>
  20. However, SQL commands executed in a row-level <code class="literal">BEFORE</code>
  21. trigger <span class="emphasis"><em>will</em></span> see the effects of data
  22. changes for rows previously processed in the same outer
  23. command. This requires caution, since the ordering of these
  24. change events is not in general predictable; a SQL command that
  25. affects multiple rows can visit the rows in any order.
  26. </p></li><li class="listitem"><p>
  27. Similarly, a row-level <code class="literal">INSTEAD OF</code> trigger will see the
  28. effects of data changes made by previous firings of <code class="literal">INSTEAD
  29. OF</code> triggers in the same outer command.
  30. </p></li><li class="listitem"><p>
  31. When a row-level <code class="literal">AFTER</code> trigger is fired, all data
  32. changes made
  33. by the outer command are already complete, and are visible to
  34. the invoked trigger function.
  35. </p></li></ul></div><p>
  36. </p><p>
  37. If your trigger function is written in any of the standard procedural
  38. languages, then the above statements apply only if the function is
  39. declared <code class="literal">VOLATILE</code>. Functions that are declared
  40. <code class="literal">STABLE</code> or <code class="literal">IMMUTABLE</code> will not see changes made by
  41. the calling command in any case.
  42. </p><p>
  43. Further information about data visibility rules can be found in
  44. <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.
  45. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="trigger-definition.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="triggers.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="trigger-interface.html">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">Home</a></td><td width="40%" align="right" valign="top"> 38.3. Writing Trigger Functions in C</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1