{"record":{"id":"8aef01cc16acc4b5","repo":"prestodb/presto","slug":"missing-column-8aef01","errorCode":"MISSING_COLUMN","errorMessage":"Column '%s' does not exist","messagePattern":"Column '(.+?)' does not exist","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/DropColumnTask.java","lineNumber":79,"sourceCode":"\n        Optional<MaterializedViewDefinition> optionalMaterializedView = metadata.getMetadataResolver(session).getMaterializedView(tableName);\n        if (optionalMaterializedView.isPresent()) {\n            if (!statement.isTableExists()) {\n                throw new SemanticException(NOT_SUPPORTED, statement, \"'%s' is a materialized view, and drop column is not supported\", tableName);\n            }\n            return immediateFuture(null);\n        }\n\n        TableHandle tableHandle = tableHandleOptional.get();\n        Identifier columnIdentifier = statement.getColumn();\n        String column = metadata.normalizeIdentifier(session, tableName.getCatalogName(), columnIdentifier.getValue());\n\n        accessControl.checkCanDropColumn(session.getRequiredTransactionId(), session.getIdentity(), session.getAccessControlContext(), tableName);\n\n        ColumnHandle columnHandle = metadata.getColumnHandles(session, tableHandle).get(column);\n        if (columnHandle == null) {\n            if (!statement.isColumnExists()) {\n                throw new SemanticException(MISSING_COLUMN, statement, \"Column '%s' does not exist\", column);\n            }\n            return immediateFuture(null);\n        }\n\n        if (metadata.getColumnMetadata(session, tableHandle, columnHandle).isHidden()) {\n            throw new SemanticException(NOT_SUPPORTED, statement, \"Cannot drop hidden column\");\n        }\n\n        if (metadata.getTableMetadata(session, tableHandle).getColumns().stream()\n                .filter(info -> !info.isHidden()).count() <= 1) {\n            throw new SemanticException(NOT_SUPPORTED, statement, \"Cannot drop the only column in a table\");\n        }\n\n        metadata.dropColumn(session, tableHandle, columnHandle);\n\n        return immediateFuture(null);\n    }\n}","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/DropColumnTask.java#L61-L97","documentation":"After access-control checks, DropColumnTask looks up the column in metadata.getColumnHandles(session, tableHandle). A null/absent handle means the column does not exist on the table; without IF COLUMN EXISTS (isColumnExists), it throws SemanticException(MISSING_COLUMN) naming the column.","triggerScenarios":"ALTER TABLE <table> DROP COLUMN <col> where <col> is not among the table's column handles and the statement did not use IF EXISTS for the column.","commonSituations":"Column already dropped in a prior run of a migration script; case-sensitivity mismatch (quoted vs unquoted identifiers); column renamed upstream; dropping a column that only exists in a view definition, not the table.","solutions":["Check the exact column name with SHOW COLUMNS FROM <table> and correct casing/spelling (quote the identifier if needed).","Add IF EXISTS for the column to make repeated migrations idempotent.","If the column was already dropped, skip the statement in your migration logic."],"exampleFix":"// before\nALTER TABLE hive.default.events DROP COLUMN TempFlag; -- actual name: tempflag\n// after\nALTER TABLE hive.default.events DROP COLUMN IF EXISTS tempflag;","handlingStrategy":"validation","validationCode":"-- Verify the column exists before DROP COLUMN\nSELECT column_name FROM information_schema.columns\nWHERE table_catalog='hive' AND table_schema='default'\n  AND table_name='events' AND lower(column_name) = 'tempflag';","typeGuard":"function columnExists(session, qname, col) {\n  return session.execute(\n    'SELECT count(*) FROM information_schema.columns WHERE table_catalog=? AND table_schema=? AND table_name=? AND lower(column_name)=lower(?)',\n    [qname.catalog, qname.schema, qname.table, col]) > 0;\n}","tryCatchPattern":"try {\n  session.execute(`ALTER TABLE ${t} DROP COLUMN IF EXISTS ${c}`);\n} catch (e) {\n  if (/Column '.*' does not exist/.test(e.message)) {\n    log.info(`Column ${c} already absent; continuing migration`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Run SHOW COLUMNS FROM <table> before every DROP COLUMN in migrations.","Make column drops idempotent with IF EXISTS.","Quote identifiers to control case sensitivity and compare case-insensitively when checking."],"tags":["presto","sql","missing-column","ddl"],"backgroundTag":"column-not-found","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}