prestodb/presto · error · PrestoException

DIVISION_BY_ZERO

DIVISION_BY_ZERO

Error message

DIVISION_BY_ZERO

What it means

Double division where the divisor is zero. Java primitive double division normally yields Infinity, but Presto's operator wrapper deliberately converts the zero-divisor condition into a DIVISION_BY_ZERO PrestoException so queries fail loudly instead of silently producing non-finite results.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/DoubleOperators.java:91

        return left - right;
    }

    @ScalarOperator(MULTIPLY)
    @SqlType(StandardTypes.DOUBLE)
    public static double multiply(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.DOUBLE) double right)
    {
        return left * right;
    }

    @ScalarOperator(DIVIDE)
    @SqlType(StandardTypes.DOUBLE)
    public static double divide(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.DOUBLE) double right)
    {
        try {
            return left / right;
        }
        catch (ArithmeticException e) {
            throw new PrestoException(DIVISION_BY_ZERO, e);
        }
    }

    @ScalarOperator(MODULUS)
    @SqlType(StandardTypes.DOUBLE)
    public static double modulus(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.DOUBLE) double right)
    {
        try {
            return left % right;
        }
        catch (ArithmeticException e) {
            throw new PrestoException(DIVISION_BY_ZERO, e);
        }
    }

    @ScalarOperator(NEGATION)
    @SqlType(StandardTypes.DOUBLE)
    public static double negate(@SqlType(StandardTypes.DOUBLE) double value)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Guard the denominator: use CASE WHEN right = 0 THEN NULL/0 ELSE left/right END
  2. Use try(x / y) in Presto SQL to return NULL on division by zero
  3. Nullify zero denominators upstream with NULLIF(y, 0)
  4. Fix the source data / filter out zero-denominator rows before the division

Example fix

// before (SQL)
SELECT revenue / clicks FROM stats
// after
SELECT revenue / NULLIF(clicks, 0) FROM stats
Defensive patterns

Strategy: validation

Validate before calling

SELECT revenue / NULLIF(clicks, 0) FROM stats

Try / catch

SELECT try(revenue / clicks) FROM stats -- NULL instead of DIVISION_BY_ZERO

Prevention

When it happens

Trigger: Executing `left / right` on two DOUBLE values where right is 0 (or evaluates to 0), via the / operator or the divide scalar operator registered in DoubleOperators.

Common situations: Aggregations producing 0 denominators (SUM returning 0), ratio computations on empty groups, ETL data with sentinel zero values in denominator columns.

Related errors


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