[EXASOL-2776] Add scalar function MIN_SCALE Created: 14.10.2020  Updated: 13.01.2022  Resolved: 20.11.2020

Status: Resolved
Project: EXASOL Roadmap
Component/s: None
Fix Version/s: Exasol 7.1.0, Exasol 7.1.alpha1

Type: New Feature Priority: Normal
Reporter: Captain EXASOL Assignee: Captain EXASOL
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Changed Behavior: Added MIN_SCALE(), a new scalar function.



We have added a new scalar function, MIN_SCALE which returns the minimum scale needed to represent the argument exactly.  This is equivalent to the number of fractional decimal digits in the value excluding trailing zeroes.

The argument must be an exact numeric (decimal).

For example:

SELECT MIN_SCALE(123.00000) S1,
       MIN_SCALE(9.99999999999) S2,
       MIN_SCALE(-0.0045600) S3;

will give the results

S1    S2    S3   
----- ----- -----
    0    11     5

This can be useful to validate data types against the containing data. Assuming the column x is defined as DECIMAL(12,10), then you can run the below query to find the maximum scale of the data. For example:

select max(ms) from (select min_scale(x) ms from t);

If the maximum scale does not match the column definition, you can adjust the scale.

Generated at Sat Jan 29 00:27:51 CET 2022 using Jira 7.13.18#713018-sha1:e1230154f8ff8cc9272975bf568fc732e806fd68.