小编use*_*258的帖子

Postgres。超出了plpgsql堆栈深度限制

我正在研究一个简单的功能,它会自动更新表中的内容。

create or replace function total() 
returns void as $$
declare
  sum int;
begin
  sum = (SELECT count(copy_id) FROM copies);
    update totalbooks
    set all_books = sum
    where num = 1;
  end;
$$ language plpgsql;
Run Code Online (Sandbox Code Playgroud)

如果我执行“ select total();” 它工作得很好,所以我做了一个函数触发器,以便它自动更新:

create or replace function total1() returns trigger as $$
begin
   perform (select total());
    return null;
end;
$$ language plpgsql;
Run Code Online (Sandbox Code Playgroud)

但是在我执行此之后:

create trigger total2
after update
on totalbooks
for each row
execute procedure total1();
Run Code Online (Sandbox Code Playgroud)

它给我一个错误信息:

ERROR:  stack depth limit exceeded
HINT:  Increase the …
Run Code Online (Sandbox Code Playgroud)

postgresql plpgsql

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

plpgsql ×1

postgresql ×1