gpt4 book ai didi

PostgreSQL 10 : With this upsert function, 如何仅在列值不同时更新?

转载 作者:行者123 更新时间:2023-11-29 14:28:39 25 4
gpt4 key购买 nike

我希望仅在 apr 不同时更新它,现在,无论它是不同还是相同,它看起来都在更新:

   INSERT INTO live_mytable (id, loan_type, apr, term, oldestyear) 
SELECT id, loan_type, apr, term, oldestyear
FROM imp_mytable
ON CONFLICT (id,loan_type,term,oldestyear) DO update
set apr = excluded.apr;

如何将此查询更改为仅在值不同时更新?

最佳答案

您可以在更新中使用 WHERE 子句:

 INSERT INTO live_mytable (id, loan_type, apr, term, oldestyear) 
SELECT id, loan_type, apr, term, oldestyear
FROM imp_mytable
ON CONFLICT (id,loan_type,term,oldestyear)
DO update
set apr = excluded.apr
WHERE
live_mytable.apr IS DISTINCT FROM
EXCLUDED.apr;

关于PostgreSQL 10 : With this upsert function, 如何仅在列值不同时更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54932543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com