{"record":{"id":"a6dc1bd2c36edd54","repo":"prestodb/presto","slug":"multiple-fields-from-subquery","errorCode":"MULTIPLE_FIELDS_FROM_SUBQUERY","errorMessage":"Multiple columns returned by subquery are not yet supported. Found %s","messagePattern":"Multiple columns returned by subquery are not yet supported\\. Found (.+?)","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java","lineNumber":1539,"sourceCode":"            setExpressionType(node, type);\n            return type; // TODO: this really should a be relation type\n        }\n\n        @Override\n        protected Type visitSubqueryExpression(SubqueryExpression node, StackableAstVisitorContext<Context> context)\n        {\n            if (context.getContext().isInLambda()) {\n                throw new SemanticException(NOT_SUPPORTED, node, \"Lambda expression cannot contain subqueries\");\n            }\n            StatementAnalyzer analyzer = statementAnalyzerFactory.apply(node);\n            Scope subqueryScope = Scope.builder()\n                    .withParent(context.getContext().getScope())\n                    .build();\n            Scope queryScope = analyzer.analyze(node.getQuery(), subqueryScope);\n\n            // Subquery should only produce one column\n            if (queryScope.getRelationType().getVisibleFieldCount() != 1) {\n                throw new SemanticException(MULTIPLE_FIELDS_FROM_SUBQUERY,\n                        node,\n                        \"Multiple columns returned by subquery are not yet supported. Found %s\",\n                        queryScope.getRelationType().getVisibleFieldCount());\n            }\n\n            Node previousNode = context.getPreviousNode().orElse(null);\n            if (previousNode instanceof InPredicate && ((InPredicate) previousNode).getValue() != node) {\n                subqueryInPredicates.add(NodeRef.of((InPredicate) previousNode));\n            }\n            else if (previousNode instanceof QuantifiedComparisonExpression) {\n                quantifiedComparisons.add(NodeRef.of((QuantifiedComparisonExpression) previousNode));\n            }\n            else {\n                scalarSubqueries.add(NodeRef.of(node));\n            }\n            sourceFields.add(queryScope.getRelationType().getFieldByIndex(0));\n            Type type = queryScope.getRelationType().getVisibleFields().stream().collect(onlyElement()).getType();\n            return setExpressionType(node, type);","sourceCodeStart":1521,"sourceCodeEnd":1557,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java#L1521-L1557","documentation":"Semantic analysis error for a subquery used in a scalar context: the subquery's SELECT list returns more than one column, but only a single-column (scalar) subquery is supported there. The %s lists the multi-column row type that was found.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java:1539 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reduce the subquery to a single column, e.g. (SELECT a FROM ...) instead of (SELECT a, b FROM ...)","Use a JOIN against the subquery when multiple columns are needed","Wrap multi-column needs in a row() or restructure the predicate"],"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"}