prestodb/presto · error · IllegalArgumentException

CHAR length must be a number

Error message

CHAR length must be a number

What it means

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.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/CharParametricType.java:52

    public String getName()
    {
        return StandardTypes.CHAR;
    }

    @Override
    public Type createType(List<TypeParameter> parameters)
    {
        if (parameters.isEmpty()) {
            return createCharType(1);
        }
        if (parameters.size() != 1) {
            throw new IllegalArgumentException("Expected at most one parameter for CHAR");
        }

        TypeParameter parameter = parameters.get(0);

        if (!parameter.isLongLiteral()) {
            throw new IllegalArgumentException("CHAR length must be a number");
        }

        try {
            return createCharType(parameter.getLongLiteral());
        }
        catch (InvalidFunctionArgumentException e) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
        }
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Provide a numeric literal length: CHAR(n).
  2. Ensure the parameter is a constant, not a column reference or expression.
  3. In code, construct the signature with a long literal parameter (e.g. LongTypeParameter).

Example fix

// before
CREATE TABLE t (c CHAR(len_col));
// after
CREATE TABLE t (c CHAR(10));
Defensive patterns

Strategy: validation

Validate before calling

if (params.size() == 1 && !params.get(0).isLongLiteral()) {
    throw new IllegalArgumentException("CHAR length must be a numeric literal");
}

Type guard

boolean isValidCharParam(TypeParameter p) { return p == null || p.isLongLiteral(); }

Try / catch

try { Type t = charParametricType.createType(params); } catch (IllegalArgumentException e) { /* supply a long literal parameter */ }

Prevention

When it happens

Trigger: Declaring CHAR with a non-numeric parameter in DDL or building a TypeParameter that is a variable/type instead of a long literal.

Common situations: Mistyping DECIMAL-like syntax for CHAR, or connector code passing a computed/expression parameter where a constant length is required.

Related errors


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