我想根据另一个字段中的条件更新数据库中的列.我可以通过两个不同的查询来实现:
update table_a
set field_1 = 'English text'
where ctid in (
select table_a.ctid from table_a
left join table_b
on table_b.a_id = table_b.id
left join table_c
on table_c.id = table_b.c_id
where table_c.language = 'EN'
);
update table_a
set field_1 = 'French text'
where ctid in (
select table_a.ctid from table_a
left join table_b
on table_b.a_id = table_b.id
left join table_c
on table_c.id = table_b.c_id
where table_c.language = 'FR'
);
然而,还有更多的语言需要考虑.我想编写一个脚本,我可以为它定义语言/文本对的映射,然后 for each 对执行上面的语句.我怎么才能接近这一点呢?
我try 为循环查找PL/pgSQL,但我无法应用我能找到的示例.