我有一些代码不会在sys_period结束时删除行,而是将它们移到历史表中。因此,我想触发一个触发器,在更新一行后,它会查看所有行并删除sys_period末尾不是无穷大的所有行。我的初步猜测如下。但是我不是SQL语法的高手,您能帮我吗?
CREATE TRIGGER {0}_delete_old_rows_trigger
AFTER UPDATE ON "{0}"
BEGIN
DELETE FROM "{0}"
WHERE upper_inf(sys_period) is FALSE
END
答案 0 :(得分:1)
这看起来可以用查询重写规则来处理:
CREATE RULE upd_to_del AS ON UPDATE TO tab
WHERE NOT upper_inf(NEW.sys_period)
DO INSTEAD
DELETE FROM tab WHERE id = NEW.id;