{"record":{"id":"1abc4ff89177a7d1","repo":"prestodb/presto","slug":"char-length-must-be-a-number","errorCode":null,"errorMessage":"CHAR length must be a number","messagePattern":"CHAR length must be a number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/CharParametricType.java","lineNumber":52,"sourceCode":"    public String getName()\n    {\n        return StandardTypes.CHAR;\n    }\n\n    @Override\n    public Type createType(List<TypeParameter> parameters)\n    {\n        if (parameters.isEmpty()) {\n            return createCharType(1);\n        }\n        if (parameters.size() != 1) {\n            throw new IllegalArgumentException(\"Expected at most one parameter for CHAR\");\n        }\n\n        TypeParameter parameter = parameters.get(0);\n\n        if (!parameter.isLongLiteral()) {\n            throw new IllegalArgumentException(\"CHAR length must be a number\");\n        }\n\n        try {\n            return createCharType(parameter.getLongLiteral());\n        }\n        catch (InvalidFunctionArgumentException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);\n        }\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":63,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/CharParametricType.java#L34-L63","documentation":"CharParametricType.createType throws this IllegalArgumentException when CHAR's single parameter is not a long literal, e.g. CHAR(varchar_col) or CHAR('x'). CHAR's length must be a numeric constant. This is a type signature construction error.","triggerScenarios":"Declaring CHAR with a non-numeric parameter in DDL or building a TypeParameter that is a variable/type instead of a long literal.","commonSituations":"Mistyping DECIMAL-like syntax for CHAR, or connector code passing a computed/expression parameter where a constant length is required.","solutions":["Provide a numeric literal length: CHAR(n).","Ensure the parameter is a constant, not a column reference or expression.","In code, construct the signature with a long literal parameter (e.g. LongTypeParameter)."],"exampleFix":"// before\nCREATE TABLE t (c CHAR(len_col));\n// after\nCREATE TABLE t (c CHAR(10));","handlingStrategy":"validation","validationCode":"if (params.size() == 1 && !params.get(0).isLongLiteral()) {\n    throw new IllegalArgumentException(\"CHAR length must be a numeric literal\");\n}","typeGuard":"boolean isValidCharParam(TypeParameter p) { return p == null || p.isLongLiteral(); }","tryCatchPattern":"try { Type t = charParametricType.createType(params); } catch (IllegalArgumentException e) { /* supply a long literal parameter */ }","preventionTips":["Always use a constant numeric length for CHAR.","Never pass column references or expressions as CHAR parameters.","In connectors, construct LongTypeParameter explicitly."],"tags":["presto","type-system","char","ddl"],"backgroundTag":"invalid-parameter-type","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"}