【Clickhouse】Code: 44. Second argument for function toDecimal64OrZero must be constant错误解决方案

错误日志:

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,那样依旧会提示该错误。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值