CREATE OR REPLACE FUNCTION aktualizujIloscPodan() RETURNS TRIGGER AS$BODY$ DECLARE n integer; sID integer;BEGINsID=0;IF (TG_OP='INSERT') THENsID = NEW."studentID";ELSIF (TG_OP='DELETE') THENsID = olD."studentID";END IF;n = COALESCE ((SELECT count("studentID") as cFROM "Podania" WHERE "studentID"=sIDGROUP BY "studentID"),0);UPDATE "Studenci" SET "licznikpodan" = n WHERE "ID"=sID;END;$BODY$LANGUAGE plpgsql;DROP TRIGGER IF EXISTS triggenPodan ON "Podania";CREATE TRIGGER triggenPodan AFTER INSERT OR DELETEON "Podania"EXECUTE PROCEDURE aktualizujIloscPodan();
当我尝试执行:
DELETE FROM "Podania"I getERROR: record "old" is not assigned yetDETAIL: The tuple structure of a not-yet-assigned record is indeterminate.CONTEXT: PL/pgsql function "aktualizujiloscpodan" line 11 at assignment********** Błąd **********ERROR: record "old" is not assigned yetStan sql:55000Szczegóły:The tuple structure of a not-yet-assigned record is indeterminate.Kontekst:PL/pgsql function "aktualizujiloscpodan" line 11 at assignment
好像不知道什么是olD或NEW.我该如何解决?
您需要使用FOR EACH ROWCREATE TRIGGER triggerPodan AFTER INSERT OR DELETEON "Podania" FOR EACH ROWEXECUTE PROCEDURE aktualizujIloscPodan();总结
以上是内存溢出为你收集整理的PostgreSQL触发器错误全部内容,希望文章能够帮你解决PostgreSQL触发器错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)