prestodb/presto · error · SemanticException

TYPE_MISMATCH

TYPE_MISMATCH

Error message

Unknown type '%s' for column '%s'

What it means

Thrown by the type-parsing helper of ALTER COLUMN SET TYPE when the type string in the statement cannot be resolved to a known Type via metadata.getType(parseTypeSignature(...)) and the parse throws IllegalArgumentException. Presto validates the requested type before applying the column type change, so an unparseable or unknown type name fails early with TYPE_MISMATCH. It guarantees the ALTER never applies a type the engine does not know.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/execution/SetColumnTypeTask.java:102

        TableHandle tableHandleOptional = tableHandle.get();
        Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandleOptional);
        ColumnHandle column = columnHandles.get(statement.getColumnName().getValue());
        if (column == null) {
            throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", statement.getColumnName());
        }
        metadata.setColumnType(session, tableHandleOptional, column, getColumnType(statement));

        return immediateFuture(null);
    }

    private Type getColumnType(SetColumnType statement)
    {
        Type type;
        try {
            type = metadata.getType(parseTypeSignature(statement.getType()));
        }
        catch (IllegalArgumentException e) {
            throw new SemanticException(TYPE_MISMATCH, statement, "Unknown type '%s' for column '%s'", statement.getType(), statement.getColumnName());
        }
        if (type.equals(UNKNOWN)) {
            throw new SemanticException(TYPE_MISMATCH, statement, "Unknown type '%s' for column '%s'", statement.getType(), statement.getColumnName());
        }
        return type;
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use SHOW COLUMNS / documentation to pick a valid Presto type name and re-run the ALTER.
  2. Check the type spelling and parameters, e.g. VARCHAR(50) instead of VARCHR(50).
  3. If mapping from another engine's type, translate it to the closest Presto type (e.g. TEXT -> VARCHAR).

Example fix

-- before
ALTER TABLE t ALTER COLUMN c SET TYPE NVARCHAR
-- after
ALTER TABLE t ALTER COLUMN c SET TYPE VARCHAR
Defensive patterns

Strategy: validation

Validate before calling

SHOW SESSION; -- not type related; instead validate type against a known list
const VALID = new Set(['VARCHAR','BIGINT','INTEGER','DOUBLE','BOOLEAN','DATE','TIMESTAMP','DECIMAL','ROW','MAP','ARRAY']);
if (!VALID.has(typeName.toUpperCase().split('(')[0])) throw new Error(`Unknown Presto type: ${typeName}`);

Type guard

function isKnownPrestoType(t) {
  return /^(varchar|bigint|integer|smallint|tinyint|double|real|boolean|date|time|timestamp|decimal|json|map|array|row|ipaddress|uuid)/i.test(t);
}

Try / catch

try {
  await run(`ALTER TABLE t ALTER COLUMN c SET TYPE ${type}`);
} catch (e) {
  if (e.message.includes("Unknown type")) {
    console.error(`Invalid type '${type}'; use a Presto-documented type`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Executing ALTER TABLE ... ALTER COLUMN col SET TYPE <type> where <type> is not a registered type name/signature (parseTypeSignature throws IllegalArgumentException).

Common situations: Misspelled type names (e.g. VARCHER); using connector-specific or engine-unsupported types; copying types from other databases (e.g. NVARCHAR, TEXT) not valid in Presto.

Related errors


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