Presto 0.127t Documentation

12.6. Decimal Functions and Operators

12.6. Decimal Functions and Operators

Decimal support is currently in BETA stage. See list of known limitations

Decimal Literals

Use DECIMAL xxxxxxx.yyyyyyy syntax to define literal of DECIMAL type.

The precision of DECIMAL type for literal will be equal to number of digits in literal (including trailing and leading zeros). The scale will be equal to number of digits in fractional part (including trailing zeros).

Example literal Data type
DECIMAL 0000012345.1234500000 DECIMAL(20, 10)

Binary Arithmetic Decimal Operators

Standard mathematical operators are supported. The table below explains precision and scale calculation rules for result. Assuming x is of type DECIMAL(xp, xs) and y is of type DECIMAL(yp, ys).
Operation Result type precision Result type scale

x + y


x - y

    1 +
      min(xs, ys) +
      min(xp - xs, yp - ys)
max(xs, ys)
x * y min(38, xp + yp) xs + ys
x / y
    xp + ys
       + max(0, ys-xs)
max(xs, ys)
x % y
min(xp - xs, yp - ys) +
max(xs, bs)
max(xs, ys)
Arithmetic operators will fail in runtime if actual result does not fit result type.

Comparison Operators

All standard comparison operators and BETWEEN operator work for DECIMAL type.

Unary Decimal Operators

The - operator performs negation. The type of result is same as type of argument.


Following type casts are currently supported for DECIMAL values:

  • to and from BIGINT
  • to and from DOUBLE
  • to and from VARCHAR
  • to and from BOOLEAN
  • to and from DECIMAL with different precision and scale