在使用Golang的PostgreSQL中,需要将日期增加1年。

huangapple go评论89阅读模式
英文:

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()

参考:Postgres UPDATE

英文:

I think that problem can be solved including the "SET" in your update statement <br />
_, err := o.Raw(&quot;UPDATE TABLE_NAME SET resetdate=resetdate + interval &#39;1 year&#39; WHERE resetdate&gt;=?&quot;,&quot;2016-12-12&quot;).Exec()

Reference: Postgres UPDATE

huangapple
  • 本文由 发表于 2016年12月6日 18:00:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/40992532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定