prestodb/presto · error · IllegalArgumentException
Invalid VARCHAR length
Error message
Invalid VARCHAR length
What it means
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.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/type/VarcharParametricType.java:60
}
if (parameters.size() != 1) {
throw new IllegalArgumentException("Expected exactly one parameter for VARCHAR");
}
TypeParameter parameter = parameters.get(0);
if (!parameter.isLongLiteral()) {
throw new IllegalArgumentException("VARCHAR length must be a number");
}
long length = parameter.getLongLiteral();
if (length == VarcharType.UNBOUNDED_LENGTH) {
return VarcharType.createUnboundedVarcharType();
}
if (length < 0 || length > VarcharType.MAX_LENGTH) {
throw new IllegalArgumentException("Invalid VARCHAR length " + length);
}
return VarcharType.createVarcharType((int) length);
}
}
View on GitHub (pinned to 55bb57d202)
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.
Example fix
// before CREATE TABLE t (notes VARCHAR(100000)); // after CREATE TABLE t (notes VARCHAR);
Defensive patterns
Strategy: validation
Validate before calling
boolean isValidVarcharLength(long len) {
return len >= 0 && len <= 65535;
} Try / catch
try {
Type t = typeManager.getParameterizedType("varchar", List.of(TypeParameter.longLiteral(len)));
} catch (IllegalArgumentException e) {
// clamp to max or fall back to unbounded VARCHAR
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: See trigger scenarios.
Related errors
- Expected exactly one parameter for VARCHAR
- Expected at most one parameter for CHAR
- CHAR length must be a number
- VARCHAR length must be a number
- CHAR length scale must be in range [0, %s]
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/19940679a3e263d0.
Report an issue: GitHub.