是否可以表达一个upsert查询,如果插入的数据与数据库中的数据相比没有任何变化,那么什么都不会发生?
目前我有:
insert into feeds (link, title, category)
values (...)
on conflict (link)
do update set (title, category, _updated)
= (..., now()::timestamp)
答案 0 :(得分:9)
您可以在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)