在plpgsql中声明一个数组并使用它



我正在尝试对ent_id数组执行3个操作(2个删除和1个更新(。这个数组是在我的脚本中的select中构建的。

CREATE
OR REPLACE FUNCTION run_script()
RETURNS VOID
AS
$$
DECLARE
all_ent bigint[];
BEGIN
select ent_id
into all_ent
from entretiens ent
where ent.ent_statut = 'T';
RAISE INFO 'Start';
delete
from documents
where ent_id in (all_ent);
delete
from comite
where ent_id in (all_ent);
update entretiens ent
set ent_statut = 'N'
where ent_id in (all_ent);
RAISE INFO 'End';
END
$$
LANGUAGE plpgsql;
SELECT run_script();

当我运行脚本时,我会出现以下错误:

ERROR: malformed array literal: "535030"
Détail : Array value must start with "{" or dimension information.

有什么建议吗?

设置为数组所选字段值:

select ARRAY(
select ent_id
from entretiens ent
where ent.ent_statut = 'T'
) into all_ent;

在查询中使用数组:

delete
from documents
where ent_id in (select aaa from unnest(all_ent) tb(aaa));

最新更新