{"record":{"id":"527d39c2414ab95a","repo":"prestodb/presto","slug":"table-function-ambiguous-return-type","errorCode":"TABLE_FUNCTION_AMBIGUOUS_RETURN_TYPE","errorMessage":"Returned relation type for table function %s is ambiguous","messagePattern":"Returned relation type for table function (.+?) is ambiguous","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":1900,"sourceCode":"                    .findFirst()\n                    .ifPresent(input -> {\n                        throw new SemanticException(TABLE_FUNCTION_IMPLEMENTATION_ERROR, \"Table function %s does not specify required input columns from table argument %s\", node.getName(), input);\n                    });\n        }\n\n        private Descriptor verifyProperColumnsDescriptor(TableFunctionInvocation node, ConnectorTableFunction function, ReturnTypeSpecification returnTypeSpecification, Optional<Descriptor> analyzedProperColumnsDescriptor)\n        {\n            switch (returnTypeSpecification.getReturnType()) {\n                case \"PASSTHROUGH\":\n                    if (analysis.isAliased(node)) {\n                        // According to SQL standard ISO/IEC 9075-2, 7.6 <table reference>, p. 409,\n                        // table alias is prohibited for a table function with ONLY PASS THROUGH returned type.\n                        throw new SemanticException(TABLE_FUNCTION_INVALID_TABLE_FUNCTION_INVOCATION, node, \"Alias specified for table function with ONLY PASS THROUGH return type\");\n                    }\n                    if (analyzedProperColumnsDescriptor.isPresent()) {\n                        // If a table function has ONLY PASS THROUGH returned type, it does not produce any proper columns,\n                        // so the function's analyze() method should not return the proper columns descriptor.\n                        throw new SemanticException(TABLE_FUNCTION_AMBIGUOUS_RETURN_TYPE, node, \"Returned relation type for table function %s is ambiguous\", node.getName());\n                    }\n                    if (function.getArguments().stream()\n                            .filter(TableArgumentSpecification.class::isInstance)\n                            .map(TableArgumentSpecification.class::cast)\n                            .noneMatch(TableArgumentSpecification::isPassThroughColumns)) {\n                        // According to SQL standard ISO/IEC 9075-2, 10.4 <routine invocation>, p. 764,\n                        // if there is no generic table parameter that specifies PASS THROUGH, then number of proper columns shall be positive.\n                        // For GENERIC_TABLE and DescribedTable returned types, this is enforced by the Descriptor constructor, which requires positive number of fields.\n                        // Here we enforce it for the remaining returned type specification: ONLY_PASS_THROUGH.\n                        throw new SemanticException(TABLE_FUNCTION_IMPLEMENTATION_ERROR, \"A table function with ONLY_PASS_THROUGH return type must have a table argument with pass-through columns.\");\n                    }\n                    return null;\n                case \"GENERIC\":\n                    // According to SQL standard ISO/IEC 9075-2, 7.6 <table reference>, p. 409,\n                    // table alias is mandatory for a polymorphic table function invocation which produces proper columns.\n                    // We don't enforce this requirement.\n                    return analyzedProperColumnsDescriptor\n                            .orElseThrow(() -> new SemanticException(TABLE_FUNCTION_MISSING_RETURN_TYPE, node, \"Cannot determine returned relation type for table function \" + node.getName()));","sourceCodeStart":1882,"sourceCodeEnd":1918,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L1882-L1918","documentation":"Analysis error for a table function: the return relation type is defined in two places at once (a statically declared return type plus a proper-columns descriptor from analyze(), or an ambiguous descriptor). The analyzer cannot decide which relation schema the function returns.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:1900 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide the return type in exactly one way: either declare it statically or return the descriptor from analyze()","Remove the redundant proper-columns specification from the invocation","Align the declared columns with the table function metadata"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}