{"record":{"id":"8eec399c6fa86af4","repo":"prestodb/presto","slug":"decimal-precision-must-be-in-range-1-38","errorCode":null,"errorMessage":"DECIMAL precision must be in range [1, 38]","messagePattern":"DECIMAL precision must be in range \\[1, 38\\]","errorType":"validation","errorClass":"InvalidFunctionArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/DecimalType.java","lineNumber":92,"sourceCode":"    public int getPrecision()\n    {\n        return precision;\n    }\n\n    public int getScale()\n    {\n        return scale;\n    }\n\n    public boolean isShort()\n    {\n        return precision <= MAX_SHORT_PRECISION;\n    }\n\n    void validatePrecisionScale(int precision, int scale, int maxPrecision)\n    {\n        if (precision <= 0 || precision > maxPrecision) {\n            throw new InvalidFunctionArgumentException(\"DECIMAL precision must be in range [1, \" + MAX_PRECISION + \"]\");\n        }\n\n        if (scale < 0 || scale > precision) {\n            throw new InvalidFunctionArgumentException(\"DECIMAL scale must be in range [0, precision]\");\n        }\n    }\n\n    private static List<TypeSignatureParameter> buildTypeParameters(int precision, int scale)\n    {\n        List<TypeSignatureParameter> typeParameters = new ArrayList<>();\n        typeParameters.add(TypeSignatureParameter.of(precision));\n        typeParameters.add(TypeSignatureParameter.of(scale));\n        return unmodifiableList(typeParameters);\n    }\n}\n","sourceCodeStart":74,"sourceCodeEnd":108,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/DecimalType.java#L74-L108","documentation":"DecimalType.validatePrecisionScale checks that DECIMAL precision is between 1 and the maximum precision (38, or 18 for short decimals when callers pass a smaller maxPrecision). Presto stores DECIMAL(p,s) with bounded precision, so any type creation with precision outside [1, MAX_PRECISION] throws InvalidFunctionArgumentException. Note the message always cites MAX_PRECISION=38 even when maxPrecision passed is smaller.","triggerScenarios":"Calling DecimalType.createType(precision, scale) or validatePrecisionScale with precision <= 0 or precision > maxPrecision (38 for full decimals, 18 when short-decimal is enforced); a connector declaring a DECIMAL column with precision 0, negative, or > 38.","commonSituations":"Schema mapping from databases allowing larger precision (e.g. DECIMAL(65) in MySQL) straight into Presto; computed precision from expressions yielding 0 or negatives due to bugs; ORC/Parquet metadata declaring out-of-range precision.","solutions":["Cap the declared precision at 38 (or coerce to DOUBLE/VARCHAR when the source exceeds 38)","Fix upstream column metadata to a supported precision before type creation","Compute precision defensively so it is always >= 1","Use Decimals.createDecimalType helpers that pair precision with the right max"],"exampleFix":"// before\nType type = DecimalType.createDecimalType(sourcePrecision, sourceScale); // sourcePrecision can be 65\n// after\nint precision = Math.min(Math.max(sourcePrecision, 1), DecimalType.MAX_PRECISION);\nint scale = Math.min(sourceScale, precision);\nType type = (precision > DecimalType.MAX_SHORT_PRECISION) ? DoubleType.DOUBLE : DecimalType.createDecimalType(precision, scale);","handlingStrategy":"validation","validationCode":"public static boolean isValidPrecision(int precision, int maxPrecision) {\n    return precision > 0 && precision <= maxPrecision;\n}\n// before createDecimalType: assert isValidPrecision(p, DecimalType.MAX_PRECISION)","typeGuard":"public static boolean isSupportedDecimalPrecision(Integer p) {\n    return p != null && p > 0 && p <= 38;\n}","tryCatchPattern":"try {\n    Type t = DecimalType.createDecimalType(precision, scale);\n} catch (InvalidFunctionArgumentException e) {\n    // degrade to DOUBLE or VARCHAR for out-of-range precision\n}","preventionTips":["Cap foreign precisions (e.g. DECIMAL(65)) at 38 or map to DOUBLE","Never compute precision with formulas that can return 0 or negatives","Coerce oversized source columns to DOUBLE/VARCHAR during schema mapping"],"tags":["presto","type-system","decimal","argument-validation"],"backgroundTag":"decimal-precision-out-of-range","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"}