prestodb/presto · error · SemanticException

TABLE_FUNCTION_INVALID_TABLE_FUNCTION_INVOCATION

TABLE_FUNCTION_INVALID_TABLE_FUNCTION_INVOCATION

Error message

Alias specified for table function with ONLY PASS THROUGH return type

What it means

Analysis error: an alias was supplied for a table function whose return type is ONLY PASS THROUGH. Pass-through functions return the descriptor of their table argument verbatim, so a table alias on the invocation itself is meaningless and is rejected.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:1895

                        });
            });
            Set<String> requiredInputs = ImmutableSet.copyOf(requiredColumns.keySet());
            allInputs.stream()
                    .filter(input -> !requiredInputs.contains(input))
                    .findFirst()
                    .ifPresent(input -> {
                        throw new SemanticException(TABLE_FUNCTION_IMPLEMENTATION_ERROR, "Table function %s does not specify required input columns from table argument %s", node.getName(), input);
                    });
        }

        private Descriptor verifyProperColumnsDescriptor(TableFunctionInvocation node, ConnectorTableFunction function, ReturnTypeSpecification returnTypeSpecification, Optional<Descriptor> analyzedProperColumnsDescriptor)
        {
            switch (returnTypeSpecification.getReturnType()) {
                case "PASSTHROUGH":
                    if (analysis.isAliased(node)) {
                        // According to SQL standard ISO/IEC 9075-2, 7.6 <table reference>, p. 409,
                        // table alias is prohibited for a table function with ONLY PASS THROUGH returned type.
                        throw new SemanticException(TABLE_FUNCTION_INVALID_TABLE_FUNCTION_INVOCATION, node, "Alias specified for table function with ONLY PASS THROUGH return type");
                    }
                    if (analyzedProperColumnsDescriptor.isPresent()) {
                        // If a table function has ONLY PASS THROUGH returned type, it does not produce any proper columns,
                        // so the function's analyze() method should not return the proper columns descriptor.
                        throw new SemanticException(TABLE_FUNCTION_AMBIGUOUS_RETURN_TYPE, node, "Returned relation type for table function %s is ambiguous", node.getName());
                    }
                    if (function.getArguments().stream()
                            .filter(TableArgumentSpecification.class::isInstance)
                            .map(TableArgumentSpecification.class::cast)
                            .noneMatch(TableArgumentSpecification::isPassThroughColumns)) {
                        // According to SQL standard ISO/IEC 9075-2, 10.4 <routine invocation>, p. 764,
                        // if there is no generic table parameter that specifies PASS THROUGH, then number of proper columns shall be positive.
                        // For GENERIC_TABLE and DescribedTable returned types, this is enforced by the Descriptor constructor, which requires positive number of fields.
                        // Here we enforce it for the remaining returned type specification: ONLY_PASS_THROUGH.
                        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.");
                    }
                    return null;
                case "GENERIC":

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Remove the alias from the table function invocation
  2. Use the column names coming from the pass-through table argument directly
  3. Wrap the invocation in a subquery with aliases if renaming is needed
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:1895 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/6f40823682fa9a95. Report an issue: GitHub.