Why does this simple query result in a "division by zero" Error?
select
case when b > 0 then sum(a / b) end
from (values (1,1),(2,1),(1,0),(2,0)) t (a,b)
group by b
I would expect the output:
case |
---|
3 |
NULL |
The only explanation I have is that postgres calculates the sum before doing the grouping and evaluating the case.