gpt4 book ai didi

database - 操作错误 : stack depth limit exceeded

转载 作者:搜寻专家 更新时间:2023-10-30 23:48:10 37 4
gpt4 key购买 nike

使用 openerp 6.1,我想触发创建两个电话调用,其日期与插入行中的日期不同(一个在 6 个月后,一个在一年后)。

我创建了这个函数:

CREATE OR REPLACE FUNCTION create_first_phonecall()
RETURNS trigger AS
$BODY$
BEGIN
select * from crm_phonecall where id= (select max(id) from crm_phonecall);
insert into crm_phonecall (name,date,state,active,user_id,x_contractnumber,x_instdate)
values('Hany', CURRENT_TIMESTAMP,'open',true,16,123456789999,CURRENT_TIMESTAMP);
return null;
END;
$BODY$
LANGUAGE 'plpgsql'

然后我创建了以下触发器:

CREATE TRIGGER create_first_phonecall
AFTER insert ON crm_phonecall
EXECUTE PROCEDURE create_first_phonecall();

但是当我尝试插入电话时,出现以下错误:

Client Traceback (most recent call last):
File "C:\Program Files (x86)\OpenERP\Server\server\openerp\addons\web\common\http.py", line 180, in dispatch
File "C:\Program Files (x86)\OpenERP\Server\server\openerp\addons\web\controllers\main.py", line 970, in create
File "C:\Program Files (x86)\OpenERP\Server\server\openerp\addons\web\common\openerplib\main.py", line 250, in proxy
File "C:\Program Files (x86)\OpenERP\Server\server\openerp\addons\web\common\openerplib\main.py", line 117, in proxy
File "C:\Program Files (x86)\OpenERP\Server\server\openerp\addons\web\common\http.py", line 608, in send


Server Traceback (most recent call last):
File "C:\Program Files (x86)\OpenERP\Server\server\openerp\addons\web\common\http.py", line 593, in send
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\netsvc.py", line 360, in dispatch_rpc
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\service\web_services.py", line 586, in dispatch
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\osv\osv.py", line 167, in execute_kw
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\osv\osv.py", line 121, in wrapper
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\osv\osv.py", line 176, in execute
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\osv\osv.py", line 164, in execute_cr
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\osv\orm.py", line 4194, in create
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\sql_db.py", line 152, in wrapper
File "C:\Program Files (x86)\OpenERP\Server\server\.\openerp\sql_db.py", line 212, in execute
OperationalError: stack depth limit exceeded
HINT: Increase the configuration parameter "max_stack_depth", after ensuring the platform's stack depth limit is adequate.
CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."res_users" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x"
SQL statement "INSERT INTO crm_phonecall (name,date,state,active,user_id,x_contractnumber,x_instdate) values('Hany', CURRENT_TIMESTAMP,'open',true,16,123456789999,CURRENT_TIMESTAMP)"
PL/pgSQL function "create_first_phonecall" line 3 at SQL statement
SQL statement "INSERT INTO crm_phonecall (name,date,state,active,user_id,x_contractnumber,x_instdate) values('Hany', CURRENT_TIMESTAMP,'open',true,16,123456789999,CURRENT_TIMESTAMP)"
PL/pgSQL function "create_first_phonecall" line 3 at SQL statement
SQL statement "INSERT INTO crm_phonecall (name,date,state,active,user_id,x_contractnumber,x_instdate) values('Hany', CURRENT_TIMESTAMP,'open',true,16,123456789999,CURRENT_TIMESTAMP)"
...

(来自 Postgres 的更多相同消息。)

有人可以帮我吗?

最佳答案

RETURN NULL 不会取消 AFTER 触发器中的操作。触发器插入一个新行,这会触发下一个 INSERT ...,从而导致无限循环。
因此,堆栈溢出 - 是的,您来对地方了。 ;)

你需要一个“中断条件”:让 Postgres 看到自动添加的行和最初插入的行之间的区别的东西。 (我的初稿只有一个 BEFORE 触发器并没有解决这个问题。)可以是任何明确定义的东西。就像一个 bool 标志:

ALTER TABLE crm_phonecall ADD COLUMN auto_insert bool;

在自动插入的行中将标志设置为 TRUE 并为此类行打断:

CREATE OR REPLACE FUNCTION create_first_phonecall()
RETURNS trigger AS
$func$
BEGIN

-- Removed incoherent code

IF NEW.auto_insert THEN
-- do nothing
ELSE
INSERT INTO crm_phonecall
(name, ..., auto_insert)
VALUES('Hany', ..., TRUE ); -- automatically inserted row
END IF;

RETURN NULL;

END
$func$ LANGUAGE plpgsql;

并使触发器BEFORE,而不是AFTER:

CREATE TRIGGER create_first_phonecall
BEFORE INSERT ON crm_phonecall
EXECUTE PROCEDURE create_first_phonecall();

备选方案:RULE

替代方案是 RULE .通常,触发器更易于处理,但 RULE 也可以避免无限循环。

关于database - 操作错误 : stack depth limit exceeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25266934/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com