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 54 55 56 57 58 59
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>40.4.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="spi.html" title="Chapter40.Server Programming Interface">
<link rel="prev" href="spi-spi-freeplan.html" title="SPI_freeplan">
<link rel="next" href="spi-examples.html" title="40.5.Examples">
<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="spi-visibility"></a>40.4.Visibility of Data Changes</h2></div></div></div>
<p> The following rules govern the visibility of data changes in
functions that use SPI (or any other C function):
</p>
<div class="itemizedlist"><ul type="disc">
<li>
<p> During the execution of an SQL command, any data changes made by
the command are invisible to the command itself. For
example, in
</p>
<pre class="programlisting">INSERT INTO a SELECT * FROM a;</pre>
<p>
the inserted rows are invisible to the <code class="command">SELECT</code>
part.
</p>
</li>
<li><p> Changes made by a command C are visible to all commands that are
started after C, no matter whether they are started inside C
(during the execution of C) or after C is done.
</p></li>
<li><p> Commands executed via SPI inside a function called by an SQL command
(either an ordinary function or a trigger) follow one or the
other of the above rules depending on the read/write flag passed
to SPI. Commands executed in read-only mode follow the first
rule: they can't see changes of the calling command. Commands executed
in read-write mode follow the second rule: they can see all changes made
so far.
</p></li>
<li><p> All standard procedural languages set the SPI read-write mode
depending on the volatility attribute of the function. Commands of
<code class="literal">STABLE</code> and <code class="literal">IMMUTABLE</code> functions are done in
read-only mode, while commands of <code class="literal">VOLATILE</code> functions are
done in read-write mode. While authors of C functions are able to
violate this convention, it's unlikely to be a good idea to do so.
</p></li>
</ul></div>
<p>
</p>
<p> The next section contains an example that illustrates the
application of these rules.
</p>
</div></body>
</html>
|