需要在Postgres的多行中连接不同的值

时间:2015-10-13 06:43:37

标签: sql postgresql triggers

我正在编写一个删除后触发器,应该这样做 假设:

2013
4023
4533

当我删除记录时,最后一位应该重建为

2012
4022

为此提供了我的psedocode:

i record;
SELECT Count(name) INTO v_CountTot FROM oca_shipmenttype WHERE oca_customerpo_id = old.oca_customerpo_id;

FOR i IN  (SELECT name FROM oca_shipmenttype WHERE oca_customerpo_id = old.oca_customerpo_id)
LOOP    
UPDATE oca_shipmenttype 
SET name = (concat(substring(i from 1 for 3),v_CountTot))
WHERE oca_shipmenttype_id = old.oca_shipmenttype_id;
END LOOP;

实际上这段代码用最后一笔交易更新所有记录 如

4022

4022

0 个答案:

没有答案