PostgreSQL触发器错误

PostgreSQL触发器错误,第1张

概述我有: 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='D 我有:
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 ROW
CREATE TRIGGER triggerPodan AFTER INSERT OR DELETEON "Podania" FOR EACH ROWEXECUTE PROCEDURE aktualizujIloscPodan();
总结

以上是内存溢出为你收集整理的PostgreSQL触发器错误全部内容,希望文章能够帮你解决PostgreSQL触发器错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1169635.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存