doudun6928 2016-12-06 10:00
浏览 203
已采纳

需要使用golang在postgreSQL中将日期添加1年

I am using golang and postgreSQL version 9.5.5 in my application. I am using github.com/lib/pq as my database driver to connect to the database. One of my fields(resetdate) have the type date. I would like to add the resetdate by 1 year. So I used the following code:

Note:I m using beego as my framework and use orm to compute my queries.

_, err := o.Raw("UPDATE resetdate=resetdate + interval  '1 year'  WHERE resetdate>=?","2016-12-12").Exec()

When I execute this I'm getting the following error:

"pq: syntax error at or near \"=\""

Appreciate any help.Thanks

  • 写回答

1条回答 默认 最新

  • dou91736 2016-12-06 11:29
    关注

    I think that problem can be solved including the "SET" in your update statement
    _, err := o.Raw("UPDATE TABLE_NAME SET resetdate=resetdate + interval '1 year' WHERE resetdate>=?","2016-12-12").Exec()

    Reference: Postgres UPDATE

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi