我的before update触发器在更新表company中的单行时抛出错误。
ERROR: relation "new" does not exist, row 7.触发器和触发器函数代码:
CREATE OR REPLACE FUNCTION public.check_company_transitivity()
RETURNS trigger
AS $$
DECLARE
cmp uuid;
head_company uuid;
audited_company uuid;
BEGIN
audited_company := (select NEW.id from NEW);
cmp:=audited_company;
head_company:='*';
while head_company is not null loop
head_company:=(select head_company from company where id=cmp);
if audited_company=head_company then
raise exception 'transitive closure';
else
cmp=head_company;
end if;
end loop;
return new;
END;
$$ LANGUAGE plpgsql;
create trigger check_company_transitivity
before update
on
public.company for each row execute procedure check_company_transitivity();我不明白问题出在哪里,如果能帮上忙,我将不胜感激。
发布于 2020-06-06 02:50:44
您可以直接使用NEW中的值
audited_company := NEW.id;https://stackoverflow.com/questions/62221985
复制相似问题