为什么触发器在 Postgresql 中不起作用
Why the Trigger is not working in Postgresql
我想用下面的触发器更新“noofdays”列。
但它不起作用,我在下面附上了触发代码和 table 结构
CREATE OR REPLACE FUNCTION update_days() RETURNS TRIGGER AS $$
BEGIN
new."noofdays":=1;
RETURN new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER calc_days before UPDATE ON bookentry FOR EACH STATEMENT EXECUTE PROCEDURE update_days();
bookid | integer | | |
loginid | integer | | |
borrowtime | timestamp without time zone | | not null | now()
returntime | timestamp without time zone | | |
noofdays | integer | | |
您需要一个行级触发器:
CREATE TRIGGER calc_days
before UPDATE ON bookentry
FOR EACH ROW --<< this
EXECUTE PROCEDURE update_days();
您应该触发行级触发器:
CREATE TRIGGER calc_days
before UPDATE ON bookentry
FOR EACH ROW --<< this
EXECUTE PROCEDURE update_days();
我想用下面的触发器更新“noofdays”列。 但它不起作用,我在下面附上了触发代码和 table 结构
CREATE OR REPLACE FUNCTION update_days() RETURNS TRIGGER AS $$
BEGIN
new."noofdays":=1;
RETURN new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER calc_days before UPDATE ON bookentry FOR EACH STATEMENT EXECUTE PROCEDURE update_days();
bookid | integer | | |
loginid | integer | | |
borrowtime | timestamp without time zone | | not null | now()
returntime | timestamp without time zone | | |
noofdays | integer | | |
您需要一个行级触发器:
CREATE TRIGGER calc_days
before UPDATE ON bookentry
FOR EACH ROW --<< this
EXECUTE PROCEDURE update_days();
您应该触发行级触发器:
CREATE TRIGGER calc_days
before UPDATE ON bookentry
FOR EACH ROW --<< this
EXECUTE PROCEDURE update_days();