Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions datafusion/sql/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,15 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
) -> Result<Vec<SelectExpr>> {
let mut prepared_select_exprs = vec![];
let mut error_builder = DataFusionErrorBuilder::new();

// Handle the case where no projection is specified but we have a valid FROM clause
// In this case, implicitly add a wildcard projection (SELECT *)
let projection = if projection.is_empty() && !empty_from {
vec![SelectItem::Wildcard(WildcardAdditionalOptions::default())]
} else {
projection
};

for expr in projection {
match self.sql_select_to_rex(expr, plan, empty_from, planner_context) {
Ok(expr) => prepared_select_exprs.push(expr),
Expand Down
55 changes: 55 additions & 0 deletions datafusion/sqllogictest/test_files/from-first.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

query I
FROM range(2)
----
0
1

query I
FROM range(2)
SELECT *
----
0
1

query I
FROM (SELECT * FROM range(2))
----
0
1

query I
FROM (FROM range(2))
----
0
1

query I
FROM range(2)
SELECT 1
----
1
1

query I
FROM range(2) as r
SELECT r.value
----
0
1
14 changes: 14 additions & 0 deletions docs/source/user-guide/sql/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ Example:
SELECT t.a FROM table AS t
```

The `FROM` clause can also come before the `SELECT` clause.
Example:

```sql
FROM table AS t
SELECT t.a
```

If the `SELECT` clause is omitted, the `FROM` clause will return all columns from the table.

```sql
FROM table
```

## WHERE clause

Example:
Expand Down