]> begriffs open source - ai-pg/blob - full-docs/txt/spi-visibility.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / spi-visibility.txt
1
2 45.5. Visibility of Data Changes #
3
4    The following rules govern the visibility of data changes in functions
5    that use SPI (or any other C function):
6      * During the execution of an SQL command, any data changes made by
7        the command are invisible to the command itself. For example, in:
8 INSERT INTO a SELECT * FROM a;
9
10        the inserted rows are invisible to the SELECT part.
11      * Changes made by a command C are visible to all commands that are
12        started after C, no matter whether they are started inside C
13        (during the execution of C) or after C is done.
14      * Commands executed via SPI inside a function called by an SQL
15        command (either an ordinary function or a trigger) follow one or
16        the other of the above rules depending on the read/write flag
17        passed to SPI. Commands executed in read-only mode follow the first
18        rule: they cannot see changes of the calling command. Commands
19        executed in read-write mode follow the second rule: they can see
20        all changes made so far.
21      * All standard procedural languages set the SPI read-write mode
22        depending on the volatility attribute of the function. Commands of
23        STABLE and IMMUTABLE functions are done in read-only mode, while
24        commands of VOLATILE functions are done in read-write mode. While
25        authors of C functions are able to violate this convention, it's
26        unlikely to be a good idea to do so.
27
28    The next section contains an example that illustrates the application
29    of these rules.