Mic*_*ent 6 sql postgresql upsert
是否可以表达一个upsert查询,如果插入的数据与数据库中已有的数据相比没有任何变化,那么什么都不会发生?
目前我有:
insert into feeds (link, title, category)
values (...)
on conflict (link)
do update set (title, category, _updated)
= (..., now()::timestamp)
Run Code Online (Sandbox Code Playgroud)
a_h*_*ame 11
您可以where在update零件中添加一个子句:
insert into feeds (link, title, category)
values (...)
on conflict (link)
do update
set (title, category, _updated) = (..., now()::timestamp)
where (feeds.title, feeds.category) is distinct from (excluded.title, excluded.category)
Run Code Online (Sandbox Code Playgroud)