Search code examples
postgresqlgoormbeego

Need the add the date by 1 year in postgreSQL using golang


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


Solution

  • 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