我设置了一个触发器来更新last_edit_date列,并且我试图忽略last_access_date列,因为该列在每次访问页面时都会更新,因此触发了“ last_edited”触发器,因为它将更新视为编辑。我正在尝试将以下代码用于触发器,但是收到以下错误:
pg_execute():查询失败:错误:列“ last_access_date”不存在
这是代码-
BEGIN
IF NOT (UPDATE(last_access_date))
THEN
NEW.last_edit_date := now();
RETURN NEW;
END IF;
END;
此外,该列确实存在,但它是与触发器关联的列(不确定是否重要)。
答案 0 :(得分:2)
如果要忽略所有修改last_access_date
的更新,可以使用:
IF NEW.last_access_date = OLD.last_access_date THEN
NEW.last_edit_date = current_timestamp;
END IF;
此外:last_access_date
使我感到紧张,因为许多更新对PostgreSQL不利。确保该列上没有索引,并且该表的fillfactor
设置为小于100,以便可以获取此列的HOT更新。