英文:
Need the add the date by 1 year in postgreSQL using golang
问题
我正在使用golang和PostgreSQL 9.5.5版本开发我的应用程序。我使用github.com/lib/pq
作为我的数据库驱动程序来连接数据库。我的一个字段(resetdate)的类型是date。我想要将resetdate增加1年。所以我使用了以下代码:
注意:我使用beego作为我的框架,并使用orm来执行查询。
_, err := o.Raw("UPDATE resetdate=resetdate + interval '1 year' WHERE resetdate>=?", "2016-12-12").Exec()
当我执行这段代码时,我得到了以下错误:
"pq: syntax error at or near "=""
感谢任何帮助。谢谢。
英文:
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
得分: 3
我认为这个问题可以通过在你的更新语句中包含"SET"来解决。
_, err := o.Raw("UPDATE TABLE_NAME SET resetdate=resetdate + interval '1 year' WHERE resetdate>=?", "2016-12-12").Exec()
英文:
I think that problem can be solved including the "SET" in your update statement <br />
_, err := o.Raw("UPDATE TABLE_NAME SET resetdate=resetdate + interval '1 year' WHERE resetdate>=?","2016-12-12").Exec()
Reference: Postgres UPDATE
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论