sql - 当更新整数的类似触发器工作正常时,更新布尔值的触发器不起作用?
问题描述
我有 2 个表,lowlevel_table 和 toplevel_table。基本上低级行包含在顶级行中
低级表
id integer
status integer
flag boolean
geom geometry point
顶层表
id integer
status integer
flag boolean
geom geometry polygon
当用户更新顶级表上一行的状态值或标志为 false 时,需要将该值传递给其中包含的所有 lowlevel_table 行。目前状态一工作正常,但即使标志一的编码非常相似,它也不起作用
工作状态触发及功能
create trigger status_update before
update of status on
toplevel_table for each row
when (new.status > old.status) execute function status_update()
CREATE OR REPLACE FUNCTION status_update()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
if new.status > old.status then
update lowlevel_table a set status = new.status where a.status < new.status
and st_contains(a.geom, st_centroid(new.geom) );
end if;
RETURN NEW;
END;
$function$
;
不工作的触发器和功能
create trigger flag_update before
update of flag on
toplevel_table for each row
when (new.flag is false) execute function flag_update()
CREATE OR REPLACE FUNCTION flag_update()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
if new.flag is false then
update lowlevel_table a set flag = new.flag where a.flag is true
and st_contains(a.geom, st_centroid(new.geom) );
end if;
RETURN NEW;
END;
$function$
;
更新查询
update toplevel_table set status = 5 where id = myid
update toplevel_table set flag = false where id = myid
我真的不明白为什么我的布尔触发器在以确切方式编写时不起作用。如何让它发挥作用?
解决方案
推荐阅读
- selenium - 使用 Selenium 抓取 Twitter 关注者
- mysql - 左外连接返回多条记录
- python - 将 Python 包安装到需要 Pip 的 Conda 环境时出现 ModuleNotFoundError 或 ImportError
- sql - 是否可以将 EXECUTE IMMEDIATE 和 USING 放入 Python 中的变量中
- sql - 如何计算 SQL Google Big Query 中不同字符串值的每周和每月出现次数?
- c - CS50 算法 - 如何解决 print_winner() 函数的循环问题
- testing - 子组件onClick函数测试用例
- javascript - Angular ESLint:任何数据类型警告
- java - 如何在 Java 中逐步评估以下表达式 **2.0+"2"**?它与 **2+"2"** 有何不同?
- python-3.x - Python Pandas DF Pivot 和 Groupby