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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog