{"record":{"id":"46663cfb5666f418","repo":"prestodb/presto","slug":"division-by-zero-46663c","errorCode":"DIVISION_BY_ZERO","errorMessage":"interval_day_to_second division by zero: %s ms / %s","messagePattern":"interval_day_to_second division by zero: (.+?) ms / (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/IntervalDayTimeOperators.java","lineNumber":139,"sourceCode":"    @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND)\n    public static long doubleMultiply(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right)\n    {\n        try {\n            return Math.addExact(\n                Math.multiplyExact((long) left, right),\n                (long) ((left - (long) left) * right));\n        }\n        catch (ArithmeticException e) {\n            throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format(\"interval_day_to_second multiply overflow: %s * %s ms\", left, right), e);\n        }\n    }\n\n    @ScalarOperator(DIVIDE)\n    @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND)\n    public static long divideByDouble(@SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long left, @SqlType(StandardTypes.DOUBLE) double right)\n    {\n        if (right == 0) {\n            throw new PrestoException(DIVISION_BY_ZERO, format(\"interval_day_to_second division by zero: %s ms / %s\", left, right));\n        }\n\n        try {\n            return multiplyByDouble(left, 1.0 / right);\n        }\n        catch (PrestoException e) {\n            throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format(\"interval_day_to_second division overflow: %s ms / %s\", left, right));\n        }\n    }\n\n    @ScalarOperator(NEGATION)\n    @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND)\n    public static long negate(@SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long value)\n    {\n        try {\n            return Math.negateExact(value);\n        }\n        catch (ArithmeticException e) {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/IntervalDayTimeOperators.java#L121-L157","documentation":"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.","triggerScenarios":"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.","commonSituations":"Dividing by a ratio or count column that is 0 (empty cohorts, zero totals); data-driven denominators from joins where no rows matched.","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"],"exampleFix":"// before\nSELECT INTERVAL '30' DAY / zero_ratio;\n// after\nSELECT INTERVAL '30' DAY / NULLIF(zero_ratio, 0.0); -- NULL instead of error, or try(... / ...)","handlingStrategy":"validation","validationCode":"-- SQL: guard the denominator before dividing\nSELECT CASE WHEN denominator = 0.0 THEN NULL ELSE INTERVAL '30' DAY / denominator END\n-- or\nSELECT INTERVAL '30' DAY / NULLIF(denominator, 0.0)","typeGuard":"public static boolean isSafeIntervalDivisor(double d) {\n    return d != 0.0;\n}","tryCatchPattern":"try {\n    long r = IntervalDayTimeOperators.divideByDouble(intervalMs, divisor);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == StandardErrorCode.DIVISION_BY_ZERO.getCode()) {\n        // return NULL or a sentinel for zero denominators\n    } else {\n        throw e;\n    }\n}","preventionTips":["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"],"tags":["presto","interval-day-to-second","division-by-zero"],"backgroundTag":"division-by-zero","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}