Adding one year to a date field in postgresql

半腔热情 提交于 2019-12-06 17:09:19

问题


I have a table in postgresql with a field_date using the syntax 'YYYY-MM-DD', I want to add a year to the field with the the sentence:

UPDATE table SET date_field = DATEADD(YEAR, 1, date_field);

but postgres return:

ERROR: column "year" does not exist

I can't see what's wrong with the sentence


回答1:


Try this:

UPDATE table SET date_field = date_field + interval '1 year'

It appears that you were trying to use SQL Server's DATEADD() function, which does not exist in Postgres.



来源:https://stackoverflow.com/questions/41864550/adding-one-year-to-a-date-field-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!