prestodb/presto · error · ArithmeticException

Decimal overflow

Error message

Decimal overflow

What it means

throwOverflowException is raised when the result of a decimal operation (multiply, add, divide, rescale, etc.) exceeds the precision/scale capacity of the target unscaled decimal representation — decimal overflow at runtime.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/type/UnscaledDecimal128Arithmetic.java:1650

        setNegativeLong(decimal, high, negative);
    }

    public static Slice pack(long low, long high, boolean negative)
    {
        Slice decimal = unscaledDecimal();
        pack(low, high, negative, decimal);
        return decimal;
    }

    public static void pack(long low, long high, boolean negative, Slice result)
    {
        setRawLong(result, 0, low);
        setRawLong(result, 1, high | (negative ? SIGN_LONG_MASK : 0));
    }

    public static void throwOverflowException()
    {
        throw new ArithmeticException("Decimal overflow");
    }

    public static int getInt(Slice decimal, int index)
    {
        int value = getRawInt(decimal, index);
        if (index == SIGN_INT_INDEX) {
            value &= ~SIGN_INT_MASK;
        }
        return value;
    }

    public static long getLong(Slice decimal, int index)
    {
        long value = getRawLong(decimal, index);
        if (index == SIGN_LONG_INDEX) {
            return unpackUnsignedLong(value);
        }
        return value;

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Cast operands to a DECIMAL with higher precision/scale before the operation
  2. Reduce the magnitude of operands
  3. Rewrite the expression to avoid the intermediate overflow
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-common/src/main/java/com/facebook/presto/common/type/UnscaledDecimal128Arithmetic.java:1650 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/6a8d0f3181985231. Report an issue: GitHub.