【问题标题】:Ignite Decimal Datatype issue点燃十进制数据类型问题
【发布时间】:2020-07-07 21:47:25
【问题描述】:

我已经在 apache ignite 中创建了如下表。

创建表测试(id号,值十进制(4,1),主键(id)

所以 value 列的精度应该为 4,比例为 1。所以无论我将插入表中的任何数据,如 1234.1234,它都应该将其修剪为 1234.1。因为我对列值的表定义是小数(4,1)。

但它没有按预期工作。

我使用的是 apache ignite 2.7.5 版。

如果我做错了什么,请告诉我。

【问题讨论】:

    标签: ignite


    【解决方案1】:

    你需要将值声明为十进制(5,1)并在插入时使用round函数

    插入测试(1, round(1234.1234,1))

    https://apacheignite-sql.readme.io/docs/round


    在您的示例中:

    Ignite 将 1234.1234 转换为 BigDecimal 并根据指定的精度进行验证。

    这里 prop.precision() 等于 4,prop.scale() 等于 1

                   BigDecimal dec = (BigDecimal)propVal;  //propVal is the value i.e. 1234.1234 in your case
    
                    if (dec.precision() > prop.precision()) { //prop are the precisions you specified i.e. (4,1)  in your case
                        throw new IgniteSQLException("Value for a column '" + prop.name() + "' is out of range. " +
                            "Maximum precision: " + prop.precision() + ", actual precision: " + dec.precision(),
                            isKey ? TOO_LONG_KEY : TOO_LONG_VALUE);
                    }
                    else if (prop.scale() != -1 &&
                        dec.scale() > prop.scale()) {
                        throw new IgniteSQLException("Value for a column '" + prop.name() + "' is out of range. " +
                            "Maximum scale : " + prop.scale() + ", actual scale: " + dec.scale(),
                            isKey ? KEY_SCALE_OUT_OF_RANGE : VALUE_SCALE_OUT_OF_RANGE);
                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      相关资源
      最近更新 更多