prestodb/presto · error · PrestoException
DIVISION_BY_ZERO
DIVISION_BY_ZERO
Error message
interval_day_to_second division by zero: %s ms / %s
What it means
Thrown by IntervalDayTimeOperators.divideByDouble when dividing an INTERVAL DAY TO SECOND by a DOUBLE that equals 0. Division by zero yields infinity, which cannot be represented as an interval millisecond long, so Presto fails fast with DIVISION_BY_ZERO instead of producing a garbage value.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/type/IntervalDayTimeOperators.java:139
@SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND)
public static long doubleMultiply(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right)
{
try {
return Math.addExact(
Math.multiplyExact((long) left, right),
(long) ((left - (long) left) * right));
}
catch (ArithmeticException e) {
throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("interval_day_to_second multiply overflow: %s * %s ms", left, right), e);
}
}
@ScalarOperator(DIVIDE)
@SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND)
public static long divideByDouble(@SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long left, @SqlType(StandardTypes.DOUBLE) double right)
{
if (right == 0) {
throw new PrestoException(DIVISION_BY_ZERO, format("interval_day_to_second division by zero: %s ms / %s", left, right));
}
try {
return multiplyByDouble(left, 1.0 / right);
}
catch (PrestoException e) {
throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("interval_day_to_second division overflow: %s ms / %s", left, right));
}
}
@ScalarOperator(NEGATION)
@SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND)
public static long negate(@SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long value)
{
try {
return Math.negateExact(value);
}
catch (ArithmeticException e) {View on GitHub (pinned to 55bb57d202)
Solutions
- Guard the denominator: NULLIF(denominator, 0.0) or a CASE WHEN right = 0 THEN ... expression
- Use try(INTERVAL '1' DAY / denominator) to get NULL instead of a failure
- Verify upstream why the denominator is zero (missing data vs legitimate value)
- Catch PrestoException with code DIVISION_BY_ZERO if handling at the engine level
Example fix
// before SELECT INTERVAL '30' DAY / zero_ratio; // after SELECT INTERVAL '30' DAY / NULLIF(zero_ratio, 0.0); -- NULL instead of error, or try(... / ...)
Defensive patterns
Strategy: validation
Validate before calling
-- SQL: guard the denominator before dividing SELECT CASE WHEN denominator = 0.0 THEN NULL ELSE INTERVAL '30' DAY / denominator END -- or SELECT INTERVAL '30' DAY / NULLIF(denominator, 0.0)
Type guard
public static boolean isSafeIntervalDivisor(double d) {
return d != 0.0;
} Try / catch
try {
long r = IntervalDayTimeOperators.divideByDouble(intervalMs, divisor);
} catch (PrestoException e) {
if (e.getErrorCode().getCode() == StandardErrorCode.DIVISION_BY_ZERO.getCode()) {
// return NULL or a sentinel for zero denominators
} else {
throw e;
}
} Prevention
- Always NULLIF or CASE-guard computed denominators
- Use try(expr) in SQL to map divide-by-zero to NULL
- Investigate why denominators reach 0 (empty joins, zero totals)
- Prefer plain integer/divide semantics checks in data validation upstream
When it happens
Trigger: DIVIDE operator with INTERVAL DAY TO SECOND left and a DOUBLE right of exactly 0.0 (or -0.0), e.g. SELECT INTERVAL '1' DAY / 0.0, or an interval divided by a computed double expression that evaluated to zero.
Common situations: Dividing by a ratio or count column that is 0 (empty cohorts, zero totals); data-driven denominators from joins where no rows matched.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/46663cfb5666f418.
Report an issue: GitHub.