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
Introduction to the PostgreSQL DATE data type When storing a date value, PostgreSQL uses the yyyy-mm-dd format e.g., 2000-12-31. It also uses this format for inserting data into a date column.
Although PostgreSQL does not provide DATEADD function similar to SQL Server, Sybase or MySQL, you can use datetime arithmetic with interval literals to get the same results.
In PostgreSQL, the make_interval() function creates an interval from years, months, weeks, days, hours, minutes and seconds fields. You provide the years, months, weeks, days, hours, minutes and/or seconds fields, and it will return an interval in the interval data type.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With