CREATE OR REPLACE FUNCTION score_audit()
RETURNS TRIGGER AS
$score_audit$
BEGIN
IF(TG_OP = 'DELETE') THEN
INSERT INTO audit_score ("USERNAME","SID","CID",updatetime,oldscore) SELECT
user,old."SID",old."CID", now() ,old."Score";
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
INSERT INTO audit_score ("USERNAME","SID","CID",updatetime,oldscore,newscore) SELECT
USER,old."SID",old."CID",current_timestamp,old."Score",new."Score"
where old."SID"=NEW."SID" AND OLD."CID"=NEW."CID";
RETURN NEW;
ELSIF (TG_OP = 'INSERT') THEN
INSERT INTO audit_score ("USERNAME","SID","CID",updatetime,oldscore,newscore) SELECT
USER,old."SID",old."CID",now(),NULL,new."Score";
RETURN NEW;
END IF;
RETURN NULL;
END;
$score_audit$ LANGUAGE plpgsql;
这是各grade表上的触发器
update修改表grade后显示
ERROR: 错误: 关系 "audit_score" 的 "updatetime" 字段不存在
LINE 1: INSERT INTO audit_score ("USERNAME","SID","CID",updatetime,o...
^
QUERY: INSERT INTO audit_score ("USERNAME","SID","CID",updatetime,oldscore,newscore) SELECT
USER,old."SID",old."CID",current_timestamp,old."Score",new."Score"
where old."SID"=NEW."SID" AND OLD."CID"=NEW."CID"
CONTEXT: 在SQL语句的第8行的PL/pgSQL函数score_audit()