{"record":{"id":"02fc298282bde39b","repo":"prestodb/presto","slug":"numeric-value-out-of-range-02fc29","errorCode":"NUMERIC_VALUE_OUT_OF_RANGE","errorMessage":"Decimal overflow","messagePattern":"Decimal overflow","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/DecimalOperators.java","lineNumber":159,"sourceCode":"        try {\n            Slice left = unscaledDecimal();\n            Slice right;\n\n            if (rescaleLeft) {\n                rescale(a, rescale, left);\n                right = b;\n            }\n            else {\n                rescale(b, rescale, left);\n                right = a;\n            }\n\n            UnscaledDecimal128Arithmetic.add(left, right, left);\n            throwIfOverflows(left);\n            return left;\n        }\n        catch (ArithmeticException e) {\n            throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, \"Decimal overflow\", e);\n        }\n    }\n\n    private static SqlScalarFunction decimalSubtractOperator()\n    {\n        TypeSignature decimalLeftSignature = parseTypeSignature(\"decimal(a_precision, a_scale)\", ImmutableSet.of(\"a_precision\", \"a_scale\"));\n        TypeSignature decimalRightSignature = parseTypeSignature(\"decimal(b_precision, b_scale)\", ImmutableSet.of(\"b_precision\", \"b_scale\"));\n        TypeSignature decimalResultSignature = parseTypeSignature(\"decimal(r_precision, r_scale)\", ImmutableSet.of(\"r_precision\", \"r_scale\"));\n\n        Signature signature = SignatureBuilder.builder()\n                .kind(SCALAR)\n                .operatorType(SUBTRACT)\n                .longVariableConstraints(\n                        longVariableExpression(\"r_precision\", \"min(38, max(a_precision - a_scale, b_precision - b_scale) + max(a_scale, b_scale) + 1)\"),\n                        longVariableExpression(\"r_scale\", \"max(a_scale, b_scale)\"))\n                .argumentTypes(decimalLeftSignature, decimalRightSignature)\n                .returnType(decimalResultSignature)\n                .build();","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/DecimalOperators.java#L141-L177","documentation":"Arithmetic error from decimal addition (internalAddLongLongLong): adding two 128-bit unscaled decimals and rescaling produced a value outside the precision-38 unscaled-decimal range, so throwIfOverflows fired and the ArithmeticException is reported as NUMERIC_VALUE_OUT_OF_RANGE 'Decimal overflow'.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/type/DecimalOperators.java:159 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reduce operand precision/scale before adding so the result fits DECIMAL(38,s)","Cast one operand to DOUBLE if exact decimal math is not required","Pre-filter rows whose operands would overflow the target precision"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}