【发布时间】:2019-05-07 12:21:46
【问题描述】:
我创建了表格
create table test ( x decimal(5,2))
然后我尝试插入一个值
insert into test values ( cast( 1000.2 as decimal(5,2) ) );
insert into test values ( cast('2000.3' as decimal(5,2) ) );
insert into test values ( cast('3000,4' as decimal(5,2) ) );
但最终 select * from test; 返回 3x NULL 值。
我做错了什么?我不敢相信上述任何陈述都行不通。
我在最近的 Cloudera 快速入门 VM 中使用 impala。
【问题讨论】:
-
精度是数字的位数。比例是数字中小数点右侧的位数。例如,数字 123.45 的精度为 5,小数位数为 2
-
@Bala 当我只插入数字而不转换其
AnalysisException: Possible loss of precision for target table 'default.test'. Expression '1000.2' (type: DECIMAL(5,1)) would need to be cast to DECIMAL(5,2) for column 'x'时,我尝试将数字舍入到insert into test values ( cast( round(3000.5) as decimal(5,2)));少于5 位,即使这最终为NULL。 -
100.2 会发生什么?
-
哦,你是对的! 1000.2 为 NULL 但 100.2 没问题。所以它也被认为是“点”!谢谢!
标签: impala cloudera-cdh