Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 触发器函数不更新ts_向量列_Postgresql_Plpgsql_Database Trigger - Fatal编程技术网

Postgresql 触发器函数不更新ts_向量列

Postgresql 触发器函数不更新ts_向量列,postgresql,plpgsql,database-trigger,Postgresql,Plpgsql,Database Trigger,我想从多个表中选择多个列,将其更新为ts_向量列。这样我们最终可以搜索所有的客户信息 问题是,它看起来像是新的。“Customer\u id”/OLD。“Customer\u id”在触发器函数中的功能与现在不同。如果我使用某个“现有客户id guid”执行sql,它就可以正常工作 CREATE FUNCTION public.onadd_onchange_customer_function() RETURNS trigger LANGUAGE 'plpgsql' COS

我想从多个表中选择多个列,将其更新为ts_向量列。这样我们最终可以搜索所有的客户信息

问题是,它看起来像是新的。“Customer\u id”/OLD。“Customer\u id”在触发器函数中的功能与现在不同。如果我使用某个“现有客户id guid”执行sql,它就可以正常工作

CREATE FUNCTION public.onadd_onchange_customer_function()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$

BEGIN


update public."Customers" set ("TextSearch") = 

(select to_tsvector(concat(a,' ', b,' ',c)) from

  (
     select concat("BarCode","FirstName" ,"MaidenName" ,"LastName" ,"SSN"  ) 
     from public."Customers"  
     where "Customer_id" = OLD."Customer_id"
  ) as a,
  (

      select string_agg(replace("CommunicationValue",' ',''), ' '::text) 
      from public."CustomerCommunications" 
      where "Active" = true  
     and "Customer_id" = OLD."Customer_id"
  )as b,
  (
      select string_agg(concat("AddressLine1",' ',"AddressLine2",' ',"AddressLine3",' ',"PostalCode",' ',"City"), ' '::text) 
      from public."CustomerAddresses" 
      where "Active" = true 
       and "Customer_id" = OLD."Customer_id
  ) as c
)
where "Customer_id" = OLD."Customer_id";


RETURN new; 
END;
$BODY$;
作为触发器运行时出错:

ERROR:  stack depth limit exceeded
HINT:  Increase the configuration parameter "max_stack_depth" (currently 2048kB), after ensuring the platform's stack depth limit is adequate.
CONTEXT:  SQL statement "update public."Customers" set ("TextSearch") = 

(select to_tsvector(concat(a,' ', b,' ',c)) from

(
select concat("BarCode","FirstName" ,"MaidenName" ,"LastName" ,"SSN"  ) 
from public."Customers"  
where "Customer_id" = OLD."Customer_id"
) as a,
(
etcetcetctec...

这个问题确实是一个无限循环

解决方案使触发器在除TextSearch列之外的所有列上运行


Thnx伙计们

所以你有一个触发器,当
更新“客户”
时触发,并再次更新
“客户”
,再次触发触发器,依此类推。在某个时候,堆栈耗尽,您会收到错误消息。也许您只是想设置
new。“TextSearch”
到某个地方并返回
new
。看起来像是无限递归。触发器更新行,这将触发触发器,这将更新行,这将触发触发器,这将。。。。如果要修改正在更新的行,可以使用BEFORE触发器,并直接修改NEW。您使用的是哪个版本的Postgres?如果您使用的是版本12+,那么计算列可能比触发器更简单。