Closed
Description
Describe the bug
When i use the
case value1 > 0 then value/value1 else 0 end as result
and got the divide by zero
To Reproduce
create table users as values (1,1),(2,2),(3,3),(0,0),(4,0);
When run
select
case when B.column1 > 0 and B.column2 > 0 then (A.column1/B.column1 - A.column2/B.column2) else 0 end as value3
from (select column1, column2 from users) as A , (select column1, column2 from users where column1 = 0) as B;
there is no issue.
But when run
select
case when B.column1 > 0 then A.column1/B.column1 else 0 end as value1,
case when B.column1 > 0 and B.column2 > 0 then A.column1/B.column1 else 0 end as value3
from (select column1, column2 from users) as A , (select column1, column2 from users where column1 = 0) as B;
there is the issue: divide by zero
Expected behavior
no exception and get the result
Additional context
I am try to find the root cause, maybe it is caused by optimizer or the execution of the physical expr.