{"record":{"id":"75fa83b1c37b4fe2","repo":"prestodb/presto","slug":"varchar-length-must-be-a-number","errorCode":null,"errorMessage":"VARCHAR length must be a number","messagePattern":"VARCHAR length must be a number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/VarcharParametricType.java","lineNumber":50,"sourceCode":"    public String getName()\n    {\n        return StandardTypes.VARCHAR;\n    }\n\n    @Override\n    public Type createType(List<TypeParameter> parameters)\n    {\n        if (parameters.isEmpty()) {\n            return createUnboundedVarcharType();\n        }\n        if (parameters.size() != 1) {\n            throw new IllegalArgumentException(\"Expected exactly one parameter for VARCHAR\");\n        }\n\n        TypeParameter parameter = parameters.get(0);\n\n        if (!parameter.isLongLiteral()) {\n            throw new IllegalArgumentException(\"VARCHAR length must be a number\");\n        }\n\n        long length = parameter.getLongLiteral();\n\n        if (length == VarcharType.UNBOUNDED_LENGTH) {\n            return VarcharType.createUnboundedVarcharType();\n        }\n\n        if (length < 0 || length > VarcharType.MAX_LENGTH) {\n            throw new IllegalArgumentException(\"Invalid VARCHAR length \" + length);\n        }\n\n        return VarcharType.createVarcharType((int) length);\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":66,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/VarcharParametricType.java#L32-L66","documentation":"The single VARCHAR type parameter must be an integer long literal, not a type parameter, wildcard, or named parameter. This is thrown when VARCHAR is given one parameter that is not a numeric length, e.g. VARCHAR(x) where x is a generic type parameter or VARCHAR(varchar(5)).","triggerScenarios":"Type signatures like VARCHAR(T) in a templated function declaration, VARCHAR(json) style misuse, or a connector that supplies a TypeParameter which is not a LongLiteral to createType.","commonSituations":"Writing parametric-type-aware custom functions with type variable placeholders copied incorrectly, plugin metadata generation bugs.","solutions":["Use a concrete integer length: VARCHAR(50).","If writing generic functions, declare the length parameter separately via @LiteralParameters('x') and use varchar(x) in the @SqlType annotation instead of a non-long TypeParameter.","Fix the connector metadata to emit long literals for VARCHAR lengths."],"exampleFix":"// before\n@SqlType(\"varchar(T)\")\n// after\n@LiteralParameters(\"x\")\n@SqlType(\"varchar(x)\")","handlingStrategy":"validation","validationCode":"boolean isValidVarcharParam(TypeParameter p) {\n    return p == null || p.isLongLiteral();\n}","typeGuard":null,"tryCatchPattern":"try {\n    Type t = typeManager.getParameterizedType(\"varchar\", params);\n} catch (IllegalArgumentException e) {\n    // handle non-long-literal parameter: substitute a concrete length\n}","preventionTips":["Always supply a numeric literal length for parameterized VARCHAR.","For generic functions, use @LiteralParameters with varchar(x) annotations instead of type variables inside VARCHAR.","Review plugin metadata generators for non-long TypeParameters."],"tags":["presto","varchar","type-system","illegal-argument"],"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"}