I want my data upto 6 decimal places in impala

Viewed 636

I have a double type column in impala while I am trying to cut it upto some decimal places I got this error ERROR: AnalysisException: No matching function with signature: truncate(DOUBLE, TINYINT). e.g select truncate(cast(0.4893617021276596 as double),7);

any workaround will be welcome

2 Answers

You can use round():

select round(col, 6)

If you actually want a truncate, then subtract 0.0000005:

select round(col - 0.0000005, 6)

Using the DECIMAL type, it is possible to represent numbers with greater precision than the FLOAT or DOUBLE types can represent.

The maximum allowed precision and scale of the DECIMAL type are both 38.

Precision is the total number of digits, regardless of the location of the decimal point.

Scale is the number of digits after the decimal place. To represent the number 8.54 without a loss of precision, you would need a DECIMAL type with precision of at least 3, and scale of at least 2.

Example: Note that the DECIMAL(17,16) type means there is a total of 17 digits, with 16 of them after the decimal point.

DECIMAL(17,16) 3.1415926535897932

You could ALTER your table with DECIMAL type as follow:

ALTER TABLE my_table CHANGE field field DECIMAL(precision, scale);

or as suggest @Gordon Linoff, you could use round() function.

Related