prestodb/presto · error · PrestoException

NUMERIC_VALUE_OUT_OF_RANGE

NUMERIC_VALUE_OUT_OF_RANGE

Error message

Decimal overflow

What it means

Arithmetic error from decimal addition (internalAddLongLongLong): adding two 128-bit unscaled decimals and rescaling produced a value outside the precision-38 unscaled-decimal range, so throwIfOverflows fired and the ArithmeticException is reported as NUMERIC_VALUE_OUT_OF_RANGE 'Decimal overflow'.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/DecimalOperators.java:159

        try {
            Slice left = unscaledDecimal();
            Slice right;

            if (rescaleLeft) {
                rescale(a, rescale, left);
                right = b;
            }
            else {
                rescale(b, rescale, left);
                right = a;
            }

            UnscaledDecimal128Arithmetic.add(left, right, left);
            throwIfOverflows(left);
            return left;
        }
        catch (ArithmeticException e) {
            throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "Decimal overflow", e);
        }
    }

    private static SqlScalarFunction decimalSubtractOperator()
    {
        TypeSignature decimalLeftSignature = parseTypeSignature("decimal(a_precision, a_scale)", ImmutableSet.of("a_precision", "a_scale"));
        TypeSignature decimalRightSignature = parseTypeSignature("decimal(b_precision, b_scale)", ImmutableSet.of("b_precision", "b_scale"));
        TypeSignature decimalResultSignature = parseTypeSignature("decimal(r_precision, r_scale)", ImmutableSet.of("r_precision", "r_scale"));

        Signature signature = SignatureBuilder.builder()
                .kind(SCALAR)
                .operatorType(SUBTRACT)
                .longVariableConstraints(
                        longVariableExpression("r_precision", "min(38, max(a_precision - a_scale, b_precision - b_scale) + max(a_scale, b_scale) + 1)"),
                        longVariableExpression("r_scale", "max(a_scale, b_scale)"))
                .argumentTypes(decimalLeftSignature, decimalRightSignature)
                .returnType(decimalResultSignature)
                .build();

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Reduce operand precision/scale before adding so the result fits DECIMAL(38,s)
  2. Cast one operand to DOUBLE if exact decimal math is not required
  3. Pre-filter rows whose operands would overflow the target precision
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/type/DecimalOperators.java:159 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/02fc298282bde39b. Report an issue: GitHub.