prestodb/presto · error · SemanticException

MISSING_COLUMN

MISSING_COLUMN

Error message

Column '%s' does not exist

What it means

SemanticException thrown by RenameColumnTask when the source column of a RENAME COLUMN does not exist in the table's column handles. Presto looks up the column by name in metadata.getColumnHandles; a missing entry means there is nothing to rename. With IF EXISTS syntax the task no-ops instead of failing.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/execution/RenameColumnTask.java:84

                throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, and rename column is not supported", tableName);
            }
            return immediateFuture(null);
        }

        TableHandle tableHandle = tableHandleOptional.get();

        Identifier sourceName = statement.getSource();
        String source = metadata.normalizeIdentifier(session, tableName.getCatalogName(), sourceName.getValue());
        Identifier targetName = statement.getTarget();
        String target = metadata.normalizeIdentifier(session, tableName.getCatalogName(), targetName.getValue());

        accessControl.checkCanRenameColumn(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);

        Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
        ColumnHandle columnHandle = columnHandles.get(source);
        if (columnHandle == null) {
            if (!statement.isColumnExists()) {
                throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", source);
            }
            return immediateFuture(null);
        }

        if (columnHandles.containsKey(target)) {
            throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, "Column '%s' already exists", target);
        }

        if (metadata.getColumnMetadata(session, tableHandle, columnHandle).isHidden()) {
            throw new SemanticException(NOT_SUPPORTED, statement, "Cannot rename hidden column");
        }

        metadata.renameColumn(session, tableHandle, columnHandle, target);

        return immediateFuture(null);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Run DESCRIBE table (or SHOW COLUMNS FROM table) to list exact column names before renaming
  2. Add IF EXISTS: ALTER TABLE IF EXISTS ... RENAME COLUMN IF EXISTS src TO dst if replay-safety matters
  3. Check identifier quoting/case: unquoted identifiers are lowercased in Presto
  4. Confirm the script isn't being re-run after a successful first execution

Example fix

-- before
ALTER TABLE shop.orders RENAME COLUMN cust_id TO customer_id; -- cust_id already renamed
-- after
ALTER TABLE shop.orders RENAME COLUMN IF EXISTS cust_id TO customer_id;
Defensive patterns

Strategy: validation

Validate before calling

ResultSet rs = stmt.executeQuery("DESCRIBE shop.orders");
Set<String> cols = new HashSet<>();
while (rs.next()) cols.add(rs.getString("Column").toLowerCase());
if (!cols.contains("cust_id")) { /* skip or abort rename */ }

Try / catch

try {
    execute("ALTER TABLE shop.orders RENAME COLUMN cust_id TO customer_id");
} catch (SemanticException e) {
    if (e.getCode() == MISSING_COLUMN) { /* already renamed or never existed — skip */ }
    else throw e;
}

Prevention

When it happens

Trigger: ALTER TABLE ... RENAME COLUMN where columnHandles.get(source) is null and statement.isColumnExists() is false. Includes case-sensitivity mismatches and quoted-identifier mistakes.

Common situations: Column already renamed by a prior statement; typo or wrong case in column name; column was dropped; script replay against a schema that has drifted.

Related errors


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