Postgresql 中文操作指南

39.2. Visibility of Data Changes #

如果您在触发器函数中执行 SQL 命令,并且这些命令访问触发器所属的表,那么您需要了解数据可见性规则,因为它们决定了这些 SQL 命令是否会看到触发器触发的 data 更改。简而言之:

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:

如果您的触发器函数使用任何标准过程语言编写,那么只有当函数被声明为 VOLATILE 时,上述说法才适用。无论如何,被声明为 STABLEIMMUTABLE 的函数将看不到调用命令所做的更改。

If your trigger function is written in any of the standard procedural languages, then the above statements apply only if the function is declared VOLATILE. Functions that are declared STABLE or IMMUTABLE will not see changes made by the calling command in any case.

有关数据可见性规则的更多信息,请参阅 Section 47.5Section 39.4 中的示例包含了这些规则的演示。

Further information about data visibility rules can be found in Section 47.5. The example in Section 39.4 contains a demonstration of these rules.