错误日志:
Code: 44. DB::Exception: Received from 127.0.0.1:1010. DB::Exception: Second argument for function toDecimal64OrZero must be constant: While processing a, toDecimal64OrZero(a, 2) AS b, c, toDecimal64OrZero(c, 2) AS d. (ILLEGAL_COLUMN)
错误日志翻译:
代码:44。DB::异常:从127.0.0.1:1010接收。DB::异常:函数toDecimal64OrZero的第二个参数必须是常量:在处理a时,toDecimal64-OrZero(a,2)AS b,c,toDecmal64OrZero(c,2)AS d。(ILLEGAL_COLUMN)
错误发生的环境:
1、多表联查。
2、查询条件中使用了俩次toDecimal64/toDecimal64OrZero函数。
3、where 条件中也使用了两次toDecimal64/toDecimal64OrZero函数。
错误定位过程:
1、 去除where条件只多表联查。可正常查询
sql如下
select a, toDecimal64OrZero(,2) b, c, toDecimal64OrZero(c,2) d from u global inner join w on u.id=w.id limit 10
查询结果如下:
2、 逐步添加各个where条件,确定问题原因:select\where 条件中均使用了toDecimal64/toDecimal64OrZero函数。
SQL如下:
select a, toDecimal64OrZero(a,2) b, c, toDecimal64OrZero(c,2) d from u global inner join w on u.id=w.id
WHERE toDecimal64OrZero(a,2) >= 200 and toDecimal64OrZero(b,2) < 300 limit 10
报错信息如下:
Code: 44. DB::Exception: Received from 172.17.8.140:9000. DB::Exception: Second argument for function toDecimal64OrZero must be constant: While processing a, toDecimal64OrZero(a, 2) AS b, c, toDecimal64OrZero(c, 2) AS d. (ILLEGAL_COLUMN)
解决方式:
由过程1可知,原始数据仅余1位小数。故,可对sql有如下几种调整方式:
1、调整where条件中的toDecimal64/toDecimal64OrZero函数保留一位小数,select中函数不变(仍旧保留两位小数)。
select a, toDecimal64OrZero(a,2) b, c, toDecimal64OrZero(c,2) d from u global inner join w on u.id=w.id
WHERE toDecimal64OrZero(a,1) >= 200 and toDecimal64OrZero(b,1) < 300 limit 10
2、调整select中的toDecimal64/toDecimal64OrZero函数保留一位小数,where条件中toDecimal64/toDecimal64OrZero函数不变(仍旧保留两位小数)。
select a, toDecimal64OrZero(a,1) b, c, toDecimal64OrZero(c,1) d from u global inner join w on u.id=w.id
WHERE toDecimal64OrZero(a,2) >= 200 and toDecimal64OrZero(b,2) < 300 limit 10
注意:
不可where\select均调整,如select a, toDecimal64OrZero(a,1) b, c, toDecimal64OrZero(c,1) d from u global inner join w on u.id=w.id WHERE toDecimal64OrZero(a,1) >= 200 and toDecimal64OrZero(b,1) < 300 limit 10
,那样依旧会提示该错误。