{"record":{"id":"866eb96b76936305","repo":"prestodb/presto","slug":"invalid-function-argument-866eb9","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"e.getMessage()","messagePattern":"e\\.getMessage\\(\\)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/DecimalParametricType.java","lineNumber":55,"sourceCode":"    }\n\n    @Override\n    public Type createType(List<TypeParameter> parameters)\n    {\n        try {\n            switch (parameters.size()) {\n                case 0:\n                    return DecimalType.createDecimalType();\n                case 1:\n                    return DecimalType.createDecimalType(parameters.get(0).getLongLiteral().intValue());\n                case 2:\n                    return DecimalType.createDecimalType(parameters.get(0).getLongLiteral().intValue(), parameters.get(1).getLongLiteral().intValue());\n                default:\n                    throw new IllegalArgumentException(\"Expected 0, 1 or 2 parameters for DECIMAL type constructor.\");\n            }\n        }\n        catch (InvalidFunctionArgumentException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);\n        }\n    }\n}\n","sourceCodeStart":37,"sourceCodeEnd":59,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/DecimalParametricType.java#L37-L59","documentation":"createType wraps DecimalType.createDecimalType calls; if those throw InvalidFunctionArgumentException (e.g. invalid precision/scale like scale > precision or non-positive precision), it is converted to a PrestoException with INVALID_FUNCTION_ARGUMENT whose message comes from the underlying exception.","triggerScenarios":"Declaring DECIMAL with illegal parameters, e.g. `DECIMAL(0)`, `DECIMAL(-5)`, `DECIMAL(10,20)` (scale > precision), via DDL, CAST, or a connector type mapping.","commonSituations":"Schema translation from other databases (e.g. NUMERIC with scale > precision); programmatic type generation with unvalidated user input; migration scripts with wrong precision order.","solutions":["Ensure 1 <= precision <= 38 and 0 <= scale <= precision in the type declaration","Swap argument order if scale and precision were reversed: DECIMAL(20,10) not DECIMAL(10,20)","Validate parameters programmatically before building the type string"],"exampleFix":"// before\nCAST(x AS DECIMAL(10,20))\n// after\nCAST(x AS DECIMAL(20,10))","handlingStrategy":"validation","validationCode":"boolean validDecimal(int precision, int scale) { return precision >= 1 && precision <= 38 && scale >= 0 && scale <= precision; }","typeGuard":null,"tryCatchPattern":"try { type = DecimalParametricType.createType(symbols); } catch (PrestoException e) { if (e.getErrorCode().getCode() == StandardErrorCode.INVALID_FUNCTION_ARGUMENT.toErrorCode().getCode()) { /* prompt user for corrected DECIMAL(p,s) */ } else { throw e; } }","preventionTips":["Enforce 1 <= p <= 38 and 0 <= s <= p when generating DECIMAL types","Map external NUMERIC types with s > p to a valid (p,s) pair","Never swap precision/scale argument order","Validate user-supplied precision/scale in UIs before building SQL"],"tags":["presto","decimal","invalid-argument","sql"],"backgroundTag":"invalid-decimal-precision-scale","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"}