{"record":{"id":"a8ae470ea454d644","repo":"prestodb/presto","slug":"division-by-zero-a8ae47","errorCode":"DIVISION_BY_ZERO","errorMessage":"DIVISION_BY_ZERO","messagePattern":"DIVISION_BY_ZERO","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/DoubleOperators.java","lineNumber":91,"sourceCode":"        return left - right;\n    }\n\n    @ScalarOperator(MULTIPLY)\n    @SqlType(StandardTypes.DOUBLE)\n    public static double multiply(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.DOUBLE) double right)\n    {\n        return left * right;\n    }\n\n    @ScalarOperator(DIVIDE)\n    @SqlType(StandardTypes.DOUBLE)\n    public static double divide(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.DOUBLE) double right)\n    {\n        try {\n            return left / right;\n        }\n        catch (ArithmeticException e) {\n            throw new PrestoException(DIVISION_BY_ZERO, e);\n        }\n    }\n\n    @ScalarOperator(MODULUS)\n    @SqlType(StandardTypes.DOUBLE)\n    public static double modulus(@SqlType(StandardTypes.DOUBLE) double left, @SqlType(StandardTypes.DOUBLE) double right)\n    {\n        try {\n            return left % right;\n        }\n        catch (ArithmeticException e) {\n            throw new PrestoException(DIVISION_BY_ZERO, e);\n        }\n    }\n\n    @ScalarOperator(NEGATION)\n    @SqlType(StandardTypes.DOUBLE)\n    public static double negate(@SqlType(StandardTypes.DOUBLE) double value)","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/DoubleOperators.java#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"Aggregations producing 0 denominators (SUM returning 0), ratio computations on empty groups, ETL data with sentinel zero values in denominator columns.","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"],"exampleFix":"// before (SQL)\nSELECT revenue / clicks FROM stats\n// after\nSELECT revenue / NULLIF(clicks, 0) FROM stats","handlingStrategy":"validation","validationCode":"SELECT revenue / NULLIF(clicks, 0) FROM stats","typeGuard":null,"tryCatchPattern":"SELECT try(revenue / clicks) FROM stats -- NULL instead of DIVISION_BY_ZERO","preventionTips":["Use NULLIF(denominator, 0) in every ratio","Prefer try() for exploratory queries on untrusted data","Check denominator aggregates (SUM/AVG) for zero results"],"tags":["division-by-zero","double","arithmetic","presto"],"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"}