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
- Guard the denominator: use CASE WHEN right = 0 THEN NULL/0 ELSE left/right END
- Use try(x / y) in Presto SQL to return NULL on division by zero
- Nullify zero denominators upstream with NULLIF(y, 0)
- 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
- Use NULLIF(denominator, 0) in every ratio
- Prefer try() for exploratory queries on untrusted data
- Check denominator aggregates (SUM/AVG) for zero results
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
- NUMERIC_VALUE_OUT_OF_RANGE
- INVALID_CAST_ARGUMENT
- NUMERIC_VALUE_OUT_OF_RANGE
- DIVISION_BY_ZERO
- DIVISION_BY_ZERO
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/a8ae470ea454d644.
Report an issue: GitHub.