{"record":{"id":"cab15326e093a29e","repo":"prestodb/presto","slug":"wildcard-without-from","errorCode":"WILDCARD_WITHOUT_FROM","errorMessage":"SELECT * not allowed in queries without FROM clause","messagePattern":"SELECT \\* not allowed in queries without FROM clause","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":4653,"sourceCode":"        }\n\n        private List<Expression> analyzeSelect(QuerySpecification node, Scope scope)\n        {\n            ImmutableList.Builder<Expression> outputExpressionBuilder = ImmutableList.builder();\n\n            for (SelectItem item : node.getSelect().getSelectItems()) {\n                if (item instanceof AllColumns) {\n                    // expand * and T.*\n                    Optional<QualifiedName> starPrefix = ((AllColumns) item).getPrefix();\n\n                    RelationType relationType = scope.getRelationType();\n                    List<Field> fields = relationType.resolveFieldsWithPrefix(starPrefix);\n                    if (fields.isEmpty()) {\n                        if (starPrefix.isPresent()) {\n                            throw new SemanticException(MISSING_TABLE, item, \"Table '%s' not found\", starPrefix.get());\n                        }\n                        if (!node.getFrom().isPresent()) {\n                            throw new SemanticException(WILDCARD_WITHOUT_FROM, item, \"SELECT * not allowed in queries without FROM clause\");\n                        }\n                        throw new SemanticException(COLUMN_NAME_NOT_SPECIFIED, item, \"SELECT * not allowed from relation that has no columns\");\n                    }\n\n                    for (Field field : fields) {\n                        int fieldIndex = relationType.indexOf(field);\n                        FieldReference expression = new FieldReference(field.getNodeLocation(), fieldIndex);\n                        outputExpressionBuilder.add(expression);\n                        ExpressionAnalysis expressionAnalysis = analyzeExpression(expression, scope);\n\n                        Type type = expressionAnalysis.getType(expression);\n                        if (node.getSelect().isDistinct() && !type.isComparable()) {\n                            throw new SemanticException(TYPE_MISMATCH, node.getSelect(), \"DISTINCT can only be applied to comparable types (actual: %s)\", type);\n                        }\n                    }\n                }\n                else if (item instanceof SingleColumn) {\n                    SingleColumn column = (SingleColumn) item;","sourceCodeStart":4635,"sourceCodeEnd":4671,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L4635-L4671","documentation":"A bare SELECT * is only valid when the query has a FROM clause providing columns to expand. If the analyzer sees SELECT * with no prefix and the statement has no FROM clause, it throws WILDCARD_WITHOUT_FROM because there is no relation whose columns the star could represent. Without FROM there is also no implicit single-row relation to select from in this position.","triggerScenarios":"Queries like SELECT *; or SELECT * with only expressions/literals and no FROM clause; generated SQL dropping the FROM clause; SELECT * inside a VALUES-only or tableless context.","commonSituations":"Programmatic query builders emitting star-selects without FROM; users expecting a dummy-table (Oracle DUAL) style query; template rendering that omits FROM when empty.","solutions":["Add a FROM clause, or replace the star with the explicit expressions/literals you actually want.","If you just need a literal row, write SELECT 1 AS x instead of SELECT *.","If generated, make the query builder emit SELECT * only when a FROM relation exists."],"exampleFix":"// before\nSELECT *;\n// after\nSELECT 1 AS one; -- or add: FROM my_table","handlingStrategy":"validation","validationCode":"if (hasSelectStar(sql) && !hasFromClause(sql)) {\n    throw new IllegalArgumentException(\"SELECT * requires a FROM clause\");\n}","typeGuard":null,"tryCatchPattern":"try { execute(sql); } catch (SemanticException e) { if (e.getCode() == WILDCARD_WITHOUT_FROM) { /* add FROM or replace * with explicit expressions */ } else { throw e; } }","preventionTips":["Only emit SELECT * together with a FROM clause in generated SQL.","Use SELECT <literals> for table-less queries instead of *.","Add a template check that FROM is non-empty when the projection is a star."],"tags":["sql","presto","select-star","from-clause"],"backgroundTag":"select-star-without-from","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"}