{"record":{"id":"fff7415fa875f102","repo":"prestodb/presto","slug":"table-function-column-not-found","errorCode":"TABLE_FUNCTION_COLUMN_NOT_FOUND","errorMessage":"Column %s is not present in the input relation","messagePattern":"Column (.+?) is not present in the input relation","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":2230,"sourceCode":"                            .orElse(NULL_DESCRIPTOR),\n                    Optional.empty());\n        }\n\n        private Field validateAndGetInputField(Expression expression, Scope inputScope)\n        {\n            QualifiedName qualifiedName;\n            if (expression instanceof Identifier) {\n                qualifiedName = QualifiedName.of(ImmutableList.of(((Identifier) expression)));\n            }\n            else if (expression instanceof DereferenceExpression) {\n                qualifiedName = getQualifiedName((DereferenceExpression) expression);\n            }\n            else {\n                throw new SemanticException(TABLE_FUNCTION_INVALID_COLUMN_REFERENCE, expression, \"Expected column reference. Actual: %s\", expression);\n            }\n            Optional<ResolvedField> field = inputScope.tryResolveField(expression, qualifiedName);\n            if (!field.isPresent() || !field.get().isLocal()) {\n                throw new SemanticException(TABLE_FUNCTION_COLUMN_NOT_FOUND, expression, \"Column %s is not present in the input relation\", expression);\n            }\n\n            return field.get().getField();\n        }\n\n        private List<List<String>> analyzeCopartitioning(List<List<QualifiedName>> copartitioning, List<TableArgumentAnalysis> tableArgumentAnalyses)\n        {\n            // map table arguments by relation names. usa a multimap, because multiple arguments can have the same value, e.g. input_1 => tpch.tiny.orders, input_2 => tpch.tiny.orders\n            ImmutableMultimap.Builder<QualifiedName, TableArgumentAnalysis> unqualifiedInputsBuilder = ImmutableMultimap.builder();\n            ImmutableMultimap.Builder<QualifiedName, TableArgumentAnalysis> qualifiedInputsBuilder = ImmutableMultimap.builder();\n            tableArgumentAnalyses.stream()\n                    .filter(argument -> argument.getName().isPresent())\n                    .forEach(argument -> {\n                        QualifiedName name = argument.getName().get();\n                        if (name.getParts().size() == 1) {\n                            unqualifiedInputsBuilder.put(name, argument);\n                        }\n                        else if (name.getParts().size() == 3) {","sourceCodeStart":2212,"sourceCodeEnd":2248,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L2212-L2248","documentation":"A column reference given to a table function argument could not be resolved as a local field of the input relation. tryResolveField either found nothing or resolved a field from an outer scope (isLocal() false), so the analyzer reports that the column does not exist in the input table argument.","triggerScenarios":"Referencing a column that is not projected by the relation passed as the table argument, or referencing a column from an outer query scope (non-local field) inside the table function invocation.","commonSituations":"Typos in column names; assuming all columns of the underlying table are visible when a subquery only projects a few; referencing outer query columns (correlated reference) from within TABLE(...).","solutions":["Verify the column exists in the passed relation with SHOW COLUMNS or DESC.","Fix the column name spelling or qualification (table.column).","If the column comes from an outer scope, project it into the input subquery explicitly.","Ensure the input subquery selects the columns the function arguments reference."],"exampleFix":"// before\nTABLE(fn(input => (SELECT a FROM t), key => missing_col))\n\n// after\nTABLE(fn(input => (SELECT a, missing_col FROM t), key => missing_col))","handlingStrategy":"validation","validationCode":"// Check that every referenced column exists in the relation passed as the table argument\nSet<String> inputColumns = describeColumns(inputRelation); // e.g. via SHOW COLUMNS metadata\nfor (String col : referencedColumns) {\n    String simple = col.contains(\".\") ? col.substring(col.lastIndexOf('.') + 1) : col;\n    if (!inputColumns.contains(simple.toLowerCase())) {\n        throw new IllegalArgumentException(\"Column \" + col + \" is not present in the input relation\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run SHOW COLUMNS on the input relation before referencing its columns.","Project all needed columns explicitly in the input subquery.","Do not rely on outer-scope columns inside TABLE(...); correlate only through the passed relation."],"tags":["sql","table-functions","column-not-found","scope"],"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"}