{"record":{"id":"19940679a3e263d0","repo":"prestodb/presto","slug":"invalid-varchar-length","errorCode":null,"errorMessage":"Invalid VARCHAR length ","messagePattern":"Invalid VARCHAR length ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/VarcharParametricType.java","lineNumber":60,"sourceCode":"        }\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":42,"sourceCodeEnd":66,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/VarcharParametricType.java#L42-L66","documentation":"VARCHAR lengths must be between 0 and VarcharType.MAX_LENGTH (65535). A negative length or one exceeding the max is rejected at type-creation time. Note the unbounded sentinel value (Integer.MAX_VALUE) is handled earlier and does not reach this check.","triggerScenarios":"DDL like CREATE TABLE t (c VARCHAR(100000)) or VARCHAR(-1), a connector reporting a column length outside 0..65535, or computed lengths passed through as literals.","commonSituations":"See trigger scenarios.","solutions":["Use lengths <= 65535, or plain VARCHAR for unbounded storage.","Replace VARCHAR with VARBYTE/binary for large payloads.","Fix schema-conversion tooling to clamp or drop oversized lengths and map to unbounded VARCHAR."],"exampleFix":"// before\nCREATE TABLE t (notes VARCHAR(100000));\n// after\nCREATE TABLE t (notes VARCHAR);","handlingStrategy":"validation","validationCode":"boolean isValidVarcharLength(long len) {\n    return len >= 0 && len <= 65535;\n}","typeGuard":null,"tryCatchPattern":"try {\n    Type t = typeManager.getParameterizedType(\"varchar\", List.of(TypeParameter.longLiteral(len)));\n} catch (IllegalArgumentException e) {\n    // clamp to max or fall back to unbounded VARCHAR\n}","preventionTips":["Clamp external schema lengths to 65535 or map oversized columns to unbounded VARCHAR during migration.","Never emit negative or sentinel lengths from connector metadata.","Remember Integer.MAX_VALUE maps to unbounded; other large values fail."],"tags":["presto","varchar","type-system","length-limit","ddl"],"backgroundTag":"invalid-varchar-length","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"}