1
votes

I have created the table in apache ignite like below.

Create table test (id number, value decimal(4,1), primary key(id)

So the value column should have a precision of 4 and a scale of 1. So whatever data I will insert into the table like 1234.1234, it should trim it to 1234.1. Because my table definition for the column value is decimal(4,1).

But it is not working as expected.

I am using apache ignite version 2.7.5.

Please let me know if I am doing anything wrong.

1

1 Answers

2
votes

You need to declare value as decimal(5,1) and use the round function when inserting

insert into test(1, round(1234.1234,1))

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



Ignite converts 1234.1234 into a BigDecimal and validates against specified precisions.

Here prop.precision() would equal 4 and prop.scale() equals 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);
                }