46

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

Emilio Galarraga
  • 659
  • 1
  • 8
  • 14

2 Answers2

90

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

select CURRENT_DATE, CURRENT_DATE + interval '1 year'

In your case you trying to do it in Transact SQL not in Postgres.

Try to use: DATEADD-> "DATE + interval '1 year'"

Galdetsky
  • 21
  • 2