我正在尝试编写 Postgres 函数,我需要执行以下操作:
DECLARE ids bigint;
Begin
-- save all john's ids. But that seems to save only one id. It may return several
select id_partner INTO ids from tb_partners WHERE name like 'john%';
-- Do a lot of things
-- only after doing things, and that may include add new johns, I need to delete the ones saved at the start of the function.
DELETE FROM tb_partners WHERE id_partner IN (ids);
问题是只能删除一个id,即使有多个要删除。
ids
. . . 好吧,可能不止一个。使用临时表:
create temporary table temp_johns_ids as
select id_partner
from tb_partners
where name like 'john%';
-- Do a lot of things
-- only after doing things, and that may include add new johns, I need to delete the ones saved at the start of the function.
delete from tb_partners
where id_partner in (select id from temp_johns_ids);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句