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

  1. Use lengths <= 65535, or plain VARCHAR for unbounded storage.
  2. Replace VARCHAR with VARBYTE/binary for large payloads.
  3. 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

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


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/19940679a3e263d0. Report an issue: GitHub.