触发器似乎忽略了我定义中的“何时条件”,但我不确定为什么。我正在运行以下内容:
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)进行了更新。由于忽略了“何时”条件,因此可以创建无限循环。
我的目的是监视地址更改,在另一个表上查找以获取经度/经度值。
PostgreSQL版本:10.6 IDE:DataGrip 2018.1.3
答案 0 :(得分:0)
您如何精确地创建和“检查”?有datagrip吗?
WHEN
条件是在Postgres 9.0中添加的。一些老的(或贫穷的)客户可能已经过时了。可以肯定的是,请使用以下命令检入pgsql:
SELECT pg_get_triggerdef(oid, true)
FROM pg_trigger
WHERE tgrelid = 'candidates'::regclass -- schema-qualify name to be sure
AND NOT tgisinternal;
任何实际的WHEN
资格以内部格式存储在pg_trigger.tgqual
中,顺便说一句。手册here中的详细信息。
您当前的search_path
是什么,表candidates
的结构是什么?
很明显,表candidates
是不合格的,而触发函数entities.tf_update_candidate_location()
具有模式限定的...您不会在不同的数据库模式中混淆同名的表,是吗? ?
此外,您可以使用以下较短的等效语法进行简化:
create trigger trigger_update_candidate_location
after update on candidates -- schema-qualify??
for each row
when (
(OLD.address1, OLD.address2, OLD.city, OLD.state, OLD.zip, OLD.country)
IS DISTINCT FROM
(NEW.address1, NEW.address2, NEW.city, NEW.state, NEW.zip, NEW.country)
)
execute procedure entities.tf_update_candidate_location();
答案 1 :(得分:0)
不幸的是,这就是DataGrip的问题。请遵循该票证,并在固定后予以通知。 https://youtrack.jetbrains.com/issue/DBE-7247