{"record":{"id":"7834081c96469645","repo":"prestodb/presto","slug":"missing-column","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/AddColumnTask.java","lineNumber":179,"sourceCode":"    private static ColumnPosition toConnectorColumnPosition(\n            AddColumn statement,\n            Metadata metadata,\n            Session session,\n            String catalogName,\n            TableHandle tableHandle,\n            Map<String, ColumnHandle> columnHandles)\n    {\n        return statement.getPosition()\n                .<ColumnPosition>map(position -> {\n                    if (position instanceof First) {\n                        return new ColumnPosition.First();\n                    }\n                    if (position instanceof After) {\n                        Identifier afterIdentifier = ((After) position).getColumn();\n                        String afterColumn = metadata.normalizeIdentifier(session, catalogName, afterIdentifier.getValue());\n                        ColumnHandle afterColumnHandle = columnHandles.get(afterColumn);\n                        if (afterColumnHandle == null) {\n                            throw new SemanticException(MISSING_COLUMN, statement, \"Column '%s' does not exist\", afterIdentifier.getValue());\n                        }\n                        // A hidden column, such as a connector's synthesized \"$path\", has no place in the table's\n                        // column order, so it cannot be positioned after even though getColumnHandles exposes it\n                        if (metadata.getColumnMetadata(session, tableHandle, afterColumnHandle).isHidden()) {\n                            throw new SemanticException(NOT_SUPPORTED, statement, \"Cannot add a column after hidden column '%s'\", afterIdentifier.getValue());\n                        }\n                        return new ColumnPosition.After(afterColumn);\n                    }\n                    throw new SemanticException(NOT_SUPPORTED, statement, \"Unsupported column position: %s\", position);\n                })\n                .orElseGet(ColumnPosition.Last::new);\n    }\n}\n","sourceCodeStart":161,"sourceCodeEnd":193,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/AddColumnTask.java#L161-L193","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Correct the column name in the AFTER clause (verify with SHOW COLUMNS FROM the table)","Remove the AFTER clause so the column is appended last (default)","Create the referenced column first if it does not yet exist"],"exampleFix":"// before\nALTER TABLE events ADD COLUMN region varchar AFTER locaton;\n// after\nALTER TABLE events ADD COLUMN region varchar AFTER location;","handlingStrategy":"validation","validationCode":"Map<String, ColumnHandle> handles = metadata.getColumnHandles(session, tableHandle);\nif (!handles.containsKey(normalize(afterColumnName))) {\n    throw new SemanticException(MISSING_COLUMN, statement, \"Column '%s' does not exist\", afterColumnName);\n}","typeGuard":"boolean columnExists(Metadata metadata, Session session, TableHandle table, String name) {\n    return metadata.getColumnHandles(session, table).containsKey(name);\n}","tryCatchPattern":"try {\n    executeAddColumn(statement);\n} catch (SemanticException e) {\n    if (e.getCode() == MISSING_COLUMN) {\n        throw new UserError(\"AFTER column not found: run SHOW COLUMNS and fix the name\", e);\n    }\n    throw e;\n}","preventionTips":["Run SHOW COLUMNS FROM <table> to confirm anchor column names before AFTER clauses","Account for identifier normalization/case rules of the catalog","Regenerate DDL scripts after column renames or drops"],"tags":["presto","ddl","missing-column"],"backgroundTag":"column-does-not-exist","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"}