PostgreSQL's Missing DateDiff Function
narrator.ai
narrator.ai
I would love to know why warehouse do this because as a data person it confuses me and is even more confusing to explain to stakeholders.
I'm not necessarily the best person to defend it, but I think it has a couple nice properties.
1. it's an integer, so can be used in group_by, comparisons, bucketing, etc
2. it aligns to commonly understood boundaries, which helps with the above.
Another way to look at the boundary issue is that it only matters when things are close. If you get a 1 and don't like it, drop down a unit (year -> months or days) instead.
Comparing years the way I did above is obviously a bit of an edge case
Once we started using it as a data warehouse I noticed that function was missing -- most other data warehouses have it. Thought it would be worth providing an implementation since date stuff is annoying to do.