- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不得不重新安装我的 Hyper-V Windows 服务器,所以我对我的 PostgreSQL 数据库进行了模式备份。
之后,我导入了架构备份。表面上看起来一切都很好。所有表、函数、触发器和序列都在那里。除了出于某种原因触发器函数不再执行任何操作。
我有两个触发器,这是两个之一。
CREATE TRIGGER t_update_modified
AFTER UPDATE
ON queue
FOR EACH ROW
EXECUTE PROCEDURE update_modified();
CREATE OR REPLACE FUNCTION update_modified()
RETURNS trigger AS
$BODY$BEGIN
NEW.modified = now();
Return NEW;
END;$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION update_modified()
OWNER TO postgres;
GRANT EXECUTE ON FUNCTION update_modified() TO postgres;
REVOKE ALL ON FUNCTION update_modified() FROM public;
我在代码中添加了 RAISE WARNING
语句来检查函数是否真的被执行了以及它们执行了多远,我确认函数确实被执行了并且它们一直执行到RETURN
语句。
我还添加了 EXCEPTION
语句来捕获任何可能抛出的异常,但没有发生这样的事情。
上面的函数应该更新已修改列的时间戳,但没有任何反应。我的两个触发器函数都曾在较旧的虚拟机上工作。 postgres
用户对相关表具有所有权限,对触发器函数具有执行权限。
这是第二个触发器:
CREATE TRIGGER t_new_task
AFTER INSERT OR UPDATE OF status
ON queue
FOR EACH ROW
EXECUTE PROCEDURE new_task();
CREATE OR REPLACE FUNCTION new_task()
RETURNS trigger AS
$BODY$BEGIN
NOTIFY newtask;
RETURN NULL;
END;$BODY$
LANGUAGE plpgsql VOLATILE LEAKPROOF
COST 100;
ALTER FUNCTION new_task()
OWNER TO postgres;
GRANT EXECUTE ON FUNCTION new_task() TO postgres;
GRANT EXECUTE ON FUNCTION new_task() TO public;
和前面一样,NOTIFY
什么都不做。没有连接的客户端收到任何通知。这也曾经在旧虚拟机上工作。
与触发器函数相关的任何内容都不会记录到日志文件中,除非我向它们添加 RAISE WARNING
语句。
在使用触发器之前,我从未遇到过此类问题。有人知道这里发生了什么吗?
我也重新创建了这些触发器,但这也没有解决问题。
更新:我创建了一个新的数据库来测试触发器。触发器在那里也不起作用,所以这个问题影响了整个 PostgreSQL 服务器。我正准备拔头发。
更新 2:重新安装 PostgreSQL 服务器并删除其数据。触发器仍然不起作用。
最佳答案
使用 BEFORE 触发器。在 AFTER 触发器中,修改行值为时已晚。如果您认为它以前有效并且是环境问题,那么您很可能在某些时候混淆了结果的解释,因为(正如您在更新中提到的)这是普遍现象。
这是手册中提到的方式,在 http://www.postgresql.org/docs/current/static/trigger-definition.html
The return value is ignored for row-level triggers fired after an operation, and so they can return NULL.
更完整的 BEFORE/AFTER 比较如下:
Typically, row-level BEFORE triggers are used for checking or modifying the data that will be inserted or updated. For example, a BEFORE trigger might be used to insert the current time into a timestamp column, or to check that two elements of the row are consistent. Row-level AFTER triggers are most sensibly used to propagate the updates to other tables, or make consistency checks against other tables. The reason for this division of labor is that an AFTER trigger can be certain it is seeing the final value of the row, while a BEFORE trigger cannot; there might be other BEFORE triggers firing after it. If you have no specific reason to make a trigger BEFORE or AFTER, the BEFORE case is more efficient, since the information about the operation doesn't have to be saved until end of statement
关于PostgreSQL 触发器停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33736395/
概述 触发器是 MySQL 的数据库对象之一,不需要程序调用或手工启动,而是由事件来触发、激活,从而实现执行,包括 INSERT 语句、UPDATE 语句和 DELETE 语句 创建触发器 1. 创建
当我为单元格获得的值是某种类型时,我试图设置一个触发器来显示文本块。 我已经成功地设法在相同的情况下显示图像,但在这种情况下我不需要图像,而是一些文本。 已注释掉行以进行测试。尝试使其工作。注释掉的代
我需要在 phpmyadmin 中为 2 个表创建一个触发器。 所以有表 stores 和 tbl_storefinder_stores。 我想从 stores 表中插入 4 个东西(名称、地址、经度
阅读目录 1、触发器 2、触发器类型 3、触发器语法 4、插入数据触发器案例 5、修改数据触发器案例
SQLite 触发器(Trigger) SQLite 的触发器是数据库的回调函数,它会在指定的数据库事件发生时自动执行/调用。以下是关于SQLite的触发器的要点:SQLite **触发器(Trig
请帮我写一个向表中添加新行的触发器。 我的数据库中有 3 个表: 地区(id,名字); id - 主要; 技术人员(身份证、姓名); id - 主要; 可用性(id、区域、技术、计数); id - p
我正在编写一个触发器来审核表中的更新和删除。我正在使用 SQL Server 2008 我的问题是, 有没有办法在不经过删除和插入表的选择阶段的情况下找出对记录采取的操作? 另一个问题是,如果记录被删
我的表: TableA (id number, state number) TableB (id number, tableAId number, state number) TableC (id n
我很少写触发器。我可以帮助设置这件事。 CREATE TRIGGER audit_tableName ON dbo.tableNameAudit AFTER CREATE, UPDATE, DELET
我之前从未在 Oracle 中创建过触发器,所以我正在寻找一些方向。 如果 ID 不在插入语句中,我想创建一个将 ID 增加 1 的触发器。 ID 应该从 10000 开始,当插入一条记录时,下一个
考虑以下两个(假设的)表 温度 * day * time * lake_name * station * temperature_f 温度_总结 * day * lake_name * station
如何在 SQL 触发器中获取更新记录的值 - 如下所示: CREATE TRIGGER TR_UpdateNew ON Users AFTER UPDATE AS BEGIN S
我是 Cassandra 新手,使用 Cassandra 3.10 并有类似的表格 create table db1.table1 (id text, trip_id text, event_time
在 MSSQL 中执行 TRUNCATE(而不是删除)时如何触发触发器 最佳答案 来自msdn : TRUNCATE TABLE cannot activate a trigger because t
我正在尝试在 sql developer 中创建一个简单的触发器,以在工资发生变化时显示工资的变化 CREATE OR REPLACE TRIGGER salary_changes BEFORE DE
我有三个表: Table1: Customers (CustomerId, Name, CustomerAddress) Table2: AccountManagers(ManagerId, Name
在 Sql Server 2005 触发器中有没有办法在执行期间获取触发器附加到的表的名称和架构? 最佳答案 SELECT OBJECT_NAME(parent_id) AS [Table],
使用 MySQL 5.5,以下触发器因错误而被拒绝: create trigger nodups before insert on `category-category` for each row b
我使用 fancybox 打开一个带有表单的弹出窗口。目前,当鼠标离开主页时,弹出窗口就会出现。为了完成这项工作,我有一个隐藏的链接标签,我用trigger()函数模拟它,单击该函数,以便该链接的hr
我的触发器触发 INSERT, UPDATE and DELETE .我需要根据触发触发器的操作从适当的内存表( inserted, deleted )插入。由于只有 inserted位于 INSER
我是一名优秀的程序员,十分优秀!