我在
postgresql中有以下代码:
CREATE OR REPLACE FUNCTION update_category() RETURNS trigger AS $newProduct$ BEGIN UPDATE category SET product_count = product_count + 1 WHERE cat_id = NEW.cat_id; INSERT INTO notification (content,type,p_id) VALUES('new product',1,NEW.p_id); RETURN NEW; END; $newProduct$LANGUAGE plpgsql; CREATE TRIGGER update_cat AFTER INSERT ON product EXECUTE PROCEDURE update_category();
将记录插入产品后,我收到错误:
[2017-03-20 16:05:05] [55000] ERROR: record "new" is not assigned yet [2017-03-20 16:05:05] Detail: The tuple structure of a not-yet-assigned record is indeterminate. [2017-03-20 16:05:05] Where: sql statement "UPDATE category SET product_count = product_count + 1 WHERE cat_id = NEW.cat_id" [2017-03-20 16:05:05] PL/pgsql function update_category() line 3 at sql statement
FOR EACH STATEMENT
正在被用来代替
FOR EACH ROW
看到我只是执行一次程序,解决方案不适用于我的情况.
谢谢你的帮助!