dpzjl68484 2016-09-26 05:21
浏览 53
已采纳

有没有办法确定行是否已更新postgres:golang

I am using postgres as my database and https://github.com/lib/pq as library. I am updating a record using prepared statement

stmt, _:= db.Prepare("UPDATE account set status='deleted' where id= $1")   
defer stmt.Close()
result, _:= stmt.Exec(accountId)
success, _:= result.RowsAffected()

And I noticed that the even if the row is already updated with the status=deleted update query always returns success=1. Is there any way we can differentiate between already updated row and not yet updated row?

  • 写回答

1条回答 默认 最新

  • dongyong5912 2016-09-26 05:37
    关注

    Yes just check in the where if the row needs updating.

    UPDATE account SET status='deleted' 
      WHERE id= $1 AND status <> 'deleted'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程