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>45.5. 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 Vsnapshot" /><link rel="prev" href="spi-spi-start-transaction.html" title="SPI_start_transaction" /><link rel="next" href="spi-examples.html" title="45.6. Examples" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">45.5. Visibility of Data Changes</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="spi-spi-start-transaction.html" title="SPI_start_transaction">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="spi.html" title="Chapter 45. Server Programming Interface">Up</a></td><th width="60%" align="center">Chapter 45. Server Programming Interface</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="spi-examples.html" title="45.6. Examples">Next</a></td></tr></table><hr /></div><div class="sect1" id="SPI-VISIBILITY"><div class="titlepage"><div><div><h2 class="title" style="clear: both">45.5. Visibility of Data Changes <a href="#SPI-VISIBILITY" class="id_link">#</a></h2></div></div></div><p>
3 The following rules govern the visibility of data changes in
4 functions that use SPI (or any other C function):
6 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
7 During the execution of an SQL command, any data changes made by
8 the command are invisible to the command itself. For
10 </p><pre class="programlisting">
11 INSERT INTO a SELECT * FROM a;
13 the inserted rows are invisible to the <code class="command">SELECT</code>
15 </p></li><li class="listitem"><p>
16 Changes made by a command C are visible to all commands that are
17 started after C, no matter whether they are started inside C
18 (during the execution of C) or after C is done.
19 </p></li><li class="listitem"><p>
20 Commands executed via SPI inside a function called by an SQL command
21 (either an ordinary function or a trigger) follow one or the
22 other of the above rules depending on the read/write flag passed
23 to SPI. Commands executed in read-only mode follow the first
24 rule: they cannot see changes of the calling command. Commands executed
25 in read-write mode follow the second rule: they can see all changes made
27 </p></li><li class="listitem"><p>
28 All standard procedural languages set the SPI read-write mode
29 depending on the volatility attribute of the function. Commands of
30 <code class="literal">STABLE</code> and <code class="literal">IMMUTABLE</code> functions are done in
31 read-only mode, while commands of <code class="literal">VOLATILE</code> functions are
32 done in read-write mode. While authors of C functions are able to
33 violate this convention, it's unlikely to be a good idea to do so.
34 </p></li></ul></div><p>
36 The next section contains an example that illustrates the
37 application of these rules.
38 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="spi-spi-start-transaction.html" title="SPI_start_transaction">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="spi.html" title="Chapter 45. Server Programming Interface">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="spi-examples.html" title="45.6. Examples">Next</a></td></tr><tr><td width="40%" align="left" valign="top">SPI_start_transaction </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 45.6. Examples</td></tr></table></div></body></html>