prestodb/presto · error · SemanticException

MISSING_COLUMN

MISSING_COLUMN

Error message

Column '%s' does not exist

What it means

Thrown by AddColumnTask.toConnectorColumnPosition when an ADD COLUMN statement uses an AFTER <column> position clause and the referenced column cannot be found among the table's column handles. The connector-facing column order cannot be resolved because the anchor column does not exist.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/execution/AddColumnTask.java:179

    private static ColumnPosition toConnectorColumnPosition(
            AddColumn statement,
            Metadata metadata,
            Session session,
            String catalogName,
            TableHandle tableHandle,
            Map<String, ColumnHandle> columnHandles)
    {
        return statement.getPosition()
                .<ColumnPosition>map(position -> {
                    if (position instanceof First) {
                        return new ColumnPosition.First();
                    }
                    if (position instanceof After) {
                        Identifier afterIdentifier = ((After) position).getColumn();
                        String afterColumn = metadata.normalizeIdentifier(session, catalogName, afterIdentifier.getValue());
                        ColumnHandle afterColumnHandle = columnHandles.get(afterColumn);
                        if (afterColumnHandle == null) {
                            throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", afterIdentifier.getValue());
                        }
                        // A hidden column, such as a connector's synthesized "$path", has no place in the table's
                        // column order, so it cannot be positioned after even though getColumnHandles exposes it
                        if (metadata.getColumnMetadata(session, tableHandle, afterColumnHandle).isHidden()) {
                            throw new SemanticException(NOT_SUPPORTED, statement, "Cannot add a column after hidden column '%s'", afterIdentifier.getValue());
                        }
                        return new ColumnPosition.After(afterColumn);
                    }
                    throw new SemanticException(NOT_SUPPORTED, statement, "Unsupported column position: %s", position);
                })
                .orElseGet(ColumnPosition.Last::new);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Correct the column name in the AFTER clause (verify with SHOW COLUMNS FROM the table)
  2. Remove the AFTER clause so the column is appended last (default)
  3. Create the referenced column first if it does not yet exist

Example fix

// before
ALTER TABLE events ADD COLUMN region varchar AFTER locaton;
// after
ALTER TABLE events ADD COLUMN region varchar AFTER location;
Defensive patterns

Strategy: validation

Validate before calling

Map<String, ColumnHandle> handles = metadata.getColumnHandles(session, tableHandle);
if (!handles.containsKey(normalize(afterColumnName))) {
    throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", afterColumnName);
}

Type guard

boolean columnExists(Metadata metadata, Session session, TableHandle table, String name) {
    return metadata.getColumnHandles(session, table).containsKey(name);
}

Try / catch

try {
    executeAddColumn(statement);
} catch (SemanticException e) {
    if (e.getCode() == MISSING_COLUMN) {
        throw new UserError("AFTER column not found: run SHOW COLUMNS and fix the name", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: `ALTER TABLE t ADD COLUMN new_col type AFTER bad_name` where bad_name is misspelled, was dropped, differs in case after normalization, or is not visible via getColumnHandles for the session/catalog.

Common situations: Typos in the AFTER clause; referencing a column that was renamed; case-sensitivity mismatches between the SQL identifier and the stored column name; scripts copied from a different table schema.

Related errors


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