我想创建一个触发器,在该触发器中,当在pgadmin 4中插入任何新员工时,更新总数
这是我的代码
CREATE TRIGGER test_trigger
AFTER INSERT ON employee
FOR EACH ROW
UPDATE counter SET counter.count = counter.count + 1
答案 0 :(得分:1)
您必须将更新放入“触发”功能
CREATE OR REPLACE FUNCTION update_counter()
RETURNS trigger
AS $$
BEGIN
UPDATE counter SET count = count + 1; --where clause?
RETURN NULL;
END;
$$ LANGUAGE plpgsql;
触发器应调用该函数。
CREATE TRIGGER test_trigger
AFTER INSERT ON employee
FOR EACH ROW
EXECUTE procedure update_counter();