【发布时间】:2019-05-01 09:50:35
【问题描述】:
触发器似乎忽略了我定义中的“何时条件”,但我不确定为什么。我正在运行以下命令:
create trigger trigger_update_candidate_location
after update on candidates
for each row
when (
OLD.address1 is distinct from NEW.address1
or
OLD.address2 is distinct from NEW.address2
or
OLD.city is distinct from NEW.city
or
OLD.state is distinct from NEW.state
or
OLD.zip is distinct from NEW.zip
or
OLD.country is distinct from NEW.country
)
execute procedure entities.tf_update_candidate_location();
但是当我再次查看它时,我得到以下信息:
-- auto-generated definition
create trigger trigger_update_candidate_location
after update
on candidates
for each row
execute procedure tf_update_candidate_location();
这是有问题的,因为我调用的过程最终会在同一张表上针对不同的列(lat/lng)进行更新。由于忽略了“何时”条件,这会产生一个无限循环。
我的目的是观察地址变化,在另一个表上查找以获取 lat/lng 值。
Postgresql 版本:10.6 IDE:DataGrip 2018.1.3
【问题讨论】:
-
不是 Postgres 忽略了你的意图,而是 DataGrip 的错误。
-
@klin 很有趣,这并不让我感到惊讶 - 你从哪里学到的?
-
Postgres 是我多年的朋友,我知道它不能做这么愚蠢的事情。
标签: postgresql plpgsql database-trigger datagrip