47.5. Visibility of Data Changes

|   47.5. Visibility of Data Changes   |              |                                        |                  |                          |
|:------------------------------------:|--------------|----------------------------------------|------------------|--------------------------|
|[Prev](spi-spi-start-transaction.html)|[Up](spi.html)|Chapter 47. Server Programming Interface|[Home](index.html)| [Next](spi-examples.html)|

---

## 47.5. Visibility of Data Changes

 The following rules govern the visibility of data changes in functions that use SPI (or any other C function):

* During the execution of an SQL command, any data changes made by the command are invisible to the command itself. For example, in:

  ```
  INSERT INTO a SELECT * FROM a;

  ```

   the inserted rows are invisible to the `SELECT` part.

* 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.

* 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 cannot see changes of the calling command. Commands executed in read-write mode follow the second rule: they can see all changes made so far.

* All standard procedural languages set the SPI read-write mode depending on the volatility attribute of the function. Commands of `STABLE` and `IMMUTABLE` functions are done in read-only mode, while commands of `VOLATILE` 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.

 The next section contains an example that illustrates the application of these rules.

---

|[Prev](spi-spi-start-transaction.html)|  [Up](spi.html)  | [Next](spi-examples.html)|
|:-------------------------------------|:----------------:|-------------------------:|
|       SPI\_start\_transaction        |[Home](index.html)|      47.6. Examples      |

 // \<![CDATA[ \<-- For SVG support if ('WebSocket' in window) { (function() { function refreshCSS() { var sheets = [].slice.call(document.getElementsByTagName("link")); var head = document.getElementsByTagName("head")[0]; for (var i = 0; i \< sheets.length; ++i) { var elem = sheets[i]; head.removeChild(elem); var rel = elem.rel; if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { var url = elem.href.replace(/(&|\\?)\_cacheOverride=\\d+/, ''); elem.href = url + (url.indexOf('?') \>= 0 ? '&' : '?') + '\_cacheOverride=' + (new Date().valueOf()); } head.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function(msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; console.log('Live reload enabled.'); })(); } // ]]\>