PostgreSQL upsert:如果字段没有改变,什么都不做
发布时间:2020-12-13 18:06:59 所属栏目:百科 来源:网络整理
导读:是否可以表达一个upsert查询,如果插入的数据与数据库中已有的数据相比没有任何变化,那么什么都不会发生? 目前我有: insert into feeds (link,title,category)values (...)on conflict (link)do update set (title,category,_updated)= (...,now()::timesta
是否可以表达一个upsert查询,如果插入的数据与数据库中已有的数据相比没有任何变化,那么什么都不会发生?
目前我有: insert into feeds (link,title,category) values (...) on conflict (link) do update set (title,category,_updated) = (...,now()::timestamp)
您可以在更新部分中添加where子句:
insert into feeds (link,category) values (...) on conflict (link) do update set (title,_updated) = (...,now()::timestamp) where (feeds.title,feeds.category) is distinct from (excluded.title,excluded.category) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |