postgresql - 触发器功能是否应该触发另一个触发器?

标签 postgresql

我有一个在插入或更新 field_1 或 field_2 之前触发的 trigger_function_a。我有另一个在插入或更新 field_3 或 field_4 之前触发的 trigger_function_b:

在插入或更新 field_1 或 field_2 之前 => trigger_function_a

在插入或更新 field_3 或 field_4 之前 => trigger_function_b

现在,trigger_function_a 修改了 field_3。应该触发 trigger_function_b 吗?我已经尝试过了,但它没有被触发。为什么?我搜索了所有可用的文档,但没有找到答案。

请不要关心这里的语法。如果我自己修改字段,触发函数会自己工作,例如。 G。通过 SQL。我在这里要问的是:如果另一个触发器函数修改了它的字段,是否应该触发一个触发器函数?

最佳答案

你是对的,trigger_function_b在这种情况下不会被调用。

the documentation :

A column-specific trigger (one defined using the UPDATE OF column_name syntax) will fire when any of its columns are listed as targets in the UPDATE command's SET list. It is possible for a column's value to change even when the trigger is not fired, because changes made to the row's contents by BEFORE UPDATE triggers are not considered. Conversely, a command such as UPDATE ... SET x = x ... will fire a trigger on column x, even though the column's value did not change.

这里的关键点是,当且仅当该列出现在 SET 列表中时,触发器才会触发。

关于postgresql - 触发器功能是否应该触发另一个触发器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40177141/

相关文章:

sql - 麻烦 GROUPing postgres 中的行

postgresql - 如何在 Windows 上启动 PostgreSQL?

json - 如何通过 "full"JSON字段查询?

postgresql - 如何在 Postgres 中使用 WHERE 子句添加索引

python - fork Django 数据库连接

sql - Postgresql 分区和 FK

multithreading - 增量数字表 postgresql 线程安全

postgresql - Redshift 错误: relation "Temp table" does not exist

arrays - 可以查询 postgresql 的列数组维度吗? (测试列是否为 int[][]?)

regex - 如何将名字拆分为姓氏和首字母