按天更新 postgresql 中的兴趣值

Update interests values in postgresql by days

我在这里需要一些帮助,至少是一个提示,关于如何将这个在 Firebird 中运行的查询写入 PostgreSQL。这是关于每天自动更新的兴趣。一直都是这样,但现在我们正在迁移,虽然我尝试了很多不同的方法,但我找不到解决方案。

execute block as 
declare variable id Integer;
begin 
for select BILL_ID from BILLS into :id do update BILLS set BILL_INTEREST_VALUE = 
TRUNC(replace(((((BILL_VALUE * BILL_PERCENT) / 100) / 30) * datediff(day, BILL_INTEREST_DATE, current_date)),',','.'), 2)where BILL_ID = :id and BILL_CLIENT_ID="+id+"
and datediff(day, BILL_INTEREST_DATE, current_date) >=  BILL_DAYS_INTEREST and 
BILL_VALUE > 0.00;
end;

我不明白为什么使用过程语言,据我所知,这可以用没有循环的单个 UPDATE 语句代替:

UPDATE BILLS 
  SET bill_interest_value = trunc( (((BILL_VALUE * BILL_PERCENT) / 100) / 30) * (current_date - bill_interest_date))
WHERE bill_id IN (SELECT bill_id FROM bills) --<< essentially useless
  AND bill_client_id = ?
  AND current_date - bill_interest_date >=  bill_days_interest 
  AND bill_value > 0.00;

上面假设 bill_interest_date 是一个 date 列(不是时间戳)