5 ms·
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
by jeffdavis 7y ago
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 ;-)
- ilikepi 7y agoPersonally 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. :)
- uhoh-itsmaciek 7y agoHey 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 ;)
- jeffdavis 7y agoAh, you got me!