Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

DATE_TRUNC('year',...) cuts out the lower-order parts of the timestamp, so I believe my query is correct. More precisely, I believe my query is incorrect in the way I intended but not in other ways ;-)


Hey Jeff! Isn't it also incorrect because

  WHERE DATE_TRUNC('year', o.ts) = '2019-01-01'::timestamptz
will filter out customers without orders even before the HAVING (because DATE_TRUNC of NULL is NULL)? I mean, I guess you're still demonstrating the perils of NULL with that ;)


Ah, you got me!


Personally I like:

    WHERE EXTRACT(YEAR FROM o.ts) = 2019
...though I imagine some people dislike the way EXTRACT treats words like YEAR as keywords. Always interesting to see which solution people choose when there are several options. :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: