Date Interval Subtract
select extract(month from (current_date - interval '1 months'))
I'd expect that to return 09. Instead it returns 10. current_date = 2018-10-31 when this was executed.
Postgresql returns 10 as I expected.
Is this a bug or expected behavior?
0
Comments
The more standardised behaviour is not adding / substracting year-to-month intervals from dates, really.
In Vertica, if you subtract INTERVAL '1 MONTH' from a date type, the result is a timestamp - and that's probably consistent with it assuming a 30 day's difference ...
ADD_MONTHS has the standard behaviour of ending up with last-of-month if the input is last-of-month. I suppose that's what you're after.
See this test here:
You'll see that the ADD_MONTHS() expressions behave as you'd expect ...
Marco
The Vertica documentation on Date/Time operators is here:
https://www.vertica.com/docs/9.1.x/HTML/index.htm#Authoring/SQLReferenceManual/LanguageElements/Operators/DateTimeOperators.htm?TocPath=SQL%20Reference%20Manual|SQL%20Language%20Elements|Operators|_____5
And I might add the result of the above script: