{"record":{"id":"f6c18f2a7569a345","repo":"prestodb/presto","slug":"column-not-found-f6c18f","errorCode":"COLUMN_NOT_FOUND","errorMessage":"Unknown field %s","messagePattern":"Unknown field (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":2493,"sourceCode":"            Map<String, ColumnHandle> columnHandles = tableColumnsMetadata.getColumnHandles();\n\n            // TODO: discover columns lazily based on where they are needed (to support connectors that can't enumerate all tables)\n            ImmutableList.Builder<Field> fields = ImmutableList.builder();\n\n            for (ColumnMetadata column : columnsMetadata) {\n                Field field = Field.newQualified(\n                        Optional.empty(),\n                        table.getName(),\n                        Optional.of(column.getName()),\n                        column.getType(),\n                        column.isHidden(),\n                        Optional.of(name),\n                        Optional.of(column.getName()),\n                        false);\n                fields.add(field);\n                ColumnHandle columnHandle = columnHandles.get(column.getName());\n                if (columnHandle == null) {\n                    throw new PrestoException(COLUMN_NOT_FOUND, format(\"Unknown field %s\", field));\n                }\n                analysis.setColumn(field, columnHandle);\n                analysis.addSourceColumns(field, ImmutableSet.of(new SourceColumn(name, column.getName())));\n            }\n\n            boolean isMergeIntoStatement = statement instanceof Merge && ((Merge) statement).getTargetTable().equals(table);\n            if (isMergeIntoStatement) {\n                // Add the target table row id field used to process the MERGE command.\n                ColumnHandle targetTableRowIdColumnHandle = metadata.getMergeTargetTableRowIdColumnHandle(session, tableHandle.get());\n                Type targetTableRowIdType = metadata.getColumnMetadata(session, tableHandle.get(), targetTableRowIdColumnHandle).getType();\n                Field targetTableRowIdField = Field.newUnqualified(table.getLocation(), \"$target_table_row_id\", targetTableRowIdType);\n                fields.add(targetTableRowIdField);\n                analysis.setColumn(targetTableRowIdField, targetTableRowIdColumnHandle);\n            }\n\n            analysis.registerTable(table, tableHandle.get());\n\n            List<Field> outputFields = fields.build();","sourceCodeStart":2475,"sourceCodeEnd":2511,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L2475-L2511","documentation":"Presto throws this PrestoException when a column listed in a table's metadata (or referenced by the statement) has no corresponding ConnectorColumnHandle in the handles returned by the connector's getColumnHandles. It means the connector knows the column name but cannot map it to a physical column handle, i.e. the catalog/schema/table metadata and the column handles are out of sync.","triggerScenarios":"Querying a table whose metadata reports a column for which metadata.getColumnHandles returns no entry — typically after the connector's metadata changed underneath a cached or stale schema, or for synthetic/internal columns the connector does not expose as handles (e.g. hidden or deleted columns in connectors like Iceberg/Delta/Hive during snapshot evolution).","commonSituations":"Concurrent table schema evolution (DROP COLUMN) while a query plan is being built; connector metadata cache holding an old column list; querying a table through a connector version that changed column handle naming; MERGE/UPDATE statements referencing a column removed on the writer.","solutions":["Refresh the connector metadata cache (invalidate cache or restart the coordinator) and retry the query","Verify the column actually exists: run SHOW COLUMNS FROM catalog.schema.table and adjust the query","Recreate/sync the table metadata if the connector's column handles are out of sync (e.g. MSCK REPAIR / connector-specific sync)","Upgrade or fix the connector plugin if getColumnHandles inconsistently omits declared columns"],"exampleFix":"// before\nSELECT deleted_col FROM catalog.schema.events; -- column dropped externally\n// after\nSHOW COLUMNS FROM catalog.schema.events;\nSELECT existing_col FROM catalog.schema.events;","handlingStrategy":"validation","validationCode":"-- confirm the column exists before querying\nSHOW COLUMNS FROM catalog.schema.table;","typeGuard":null,"tryCatchPattern":"try {\n    return session.execute(query);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == COLUMN_NOT_FOUND.getCode()) {\n        // refresh metadata cache / re-run SHOW COLUMNS and rebuild query\n    }\n    throw e;\n}","preventionTips":["Run SHOW COLUMNS before generating queries against tables subject to schema evolution","Avoid long-lived cached schemas in query builders; fetch metadata per query","Coordinate DROP COLUMN changes with downstream query consumers","Pin connector versions across the cluster to keep handle naming consistent"],"tags":["sql","column-not-found","metadata","connector"],"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"}