+ -
当前位置:首页 → 问答吧 → case 中过滤了除数为0的情况,但postgresql是否还会检测除数是否为0?

case 中过滤了除数为0的情况,但postgresql是否还会检测除数是否为0?

时间:2010-10-18

来源:互联网

有个sql语句,类似于

select
case  when aa!=0 then bb/aa end, aa, bb from ttt;

同样的语句以及同样的数据,在oracle中正常运行,在postgresql(事实上我用的是greenplum)中却报“ERROR:  cannot take logarithm of zero  (seg4 gpsdw5-1:50001 pid=14552)”的错误,个人感觉应该是除数为0造成的

请教一下各位大侠,postgresql中是不是不管你前面有否case过滤,查询时都会检测除数是否为0的情况?

如果确实如此,遇到这种情况,我应该怎么改写sql比较好呢?

作者: lonyce   发布时间: 2010-10-18

在一个表中实测返回的
select case when aa!= 0 then bb/aa end, bb, aa from ttt;
            case            |  bb| aa
----------------------------+-----------+---------
     0.00000000000000000000 |      0.00 |     500
     0.00000000000000000000 |      0.00 |     500
     0.00000000000000000000 |      0.00 |     500
                            |  60000.00 |       0
                            |  60000.00 |       0
                            |  60000.00 |       0
                            |  60000.00 |       0
                            |  60000.00 |       0
     0.00000000000000000000 |      0.00 |    1000
     0.00000000000000000000 |      0.00 |    1000
     0.00000000000000000000 |      0.00 |    1000

作者: congli   发布时间: 2010-10-18