1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>33.2.Visibility of Data Changes</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="triggers.html" title="Chapter33.Triggers">
<link rel="prev" href="triggers.html" title="Chapter33.Triggers">
<link rel="next" href="trigger-interface.html" title="33.3.Writing Trigger Functions in C">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="trigger-datachanges"></a>33.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 type="disc">
<li><p> Statement-level triggers follow simple visibility rules: none of
the changes made by a statement are visible to statement-level
triggers that are invoked before the statement, whereas all
modifications are visible to statement-level after triggers.
</p></li>
<li><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 before trigger, because
it hasn't happened yet.
</p></li>
<li><p> However, SQL commands executed in a row-level before
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 may visit the rows in any order.
</p></li>
<li><p> When a row-level after 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> Further information about data visibility rules can be found in
<a href="spi-visibility.html" title="40.4.Visibility of Data Changes">Section40.4, “Visibility of Data Changes”</a>. The example in <a href="trigger-example.html" title="33.4.A Complete Example">Section33.4, “A Complete Example”</a> contains a demonstration of these rules.
</p>
</div></body>
</html>
|