Hello PostgreSQL experts.
I'm trying to understand why these 2 Boolean expressions return different results.
The first returns TRUE whereas the second returns FALSE.
SELECT CAST('2019-01-01T12:00:00' AS TIMESTAMP) - CAST('2018-01-01T13:00:00' AS TIMESTAMP) <= INTERVAL '365 DAYS',
CAST('2019-01-01T12:00:00' AS TIMESTAMP) - CAST('2018-01-01T13:00:00' AS TIMESTAMP) <= INTERVAL '1 YEAR';
Neither 2019 nor 2018 were leap years.
I expected that for non-leap years, a 1 year interval will be equivalent to a 365 day interval, but I'm obviously wrong.
Tested with PostgreSQL 15.
Your help will be highly appreciated!
Edit: So looks like this is more of a bug than it is a feature. "IEC/ISO 9075-2:2016 SQL foundations" defines 2 types of intervals. One is called year-month interval and the other day-time interval. Each type is comparable only with itself. Therefore, the 2nd predicate should have raised an error for incompatible types. This would have saved a lot of headaches for everyone who uses it. If there are PostgreSQL contributors reading this, I think this should be considered for implementation in a future release.