-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support from-first SQL syntax #17295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I noticed in apache#17278 that `from` without an explicit projection did not work. This should fix it
alamb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯 -- thank you @simonvandel
I also verified duckdb does support this
D create table t(x int);
D insert into t values (1);
D from t;
┌───────┐
│ x │
│ int32 │
├───────┤
│ 1 │
└───────┘@Jefffrey or @jonahgao -- any concern about supporting this syntax?
Jefffrey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used this in DuckDB before and agree it's pretty slick & handy;
Maybe need to update the SQL reference docs with this new behaviour?
I added some documentation in 9f1b436 |
Jefffrey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR apache#17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes apache#17513
|
@xudong963 found this PR seems to have introduced a regression @adriangb has a proposed PR up to fix: |
|
@alamb we discussed a bit in #17520 (comment), I'm not sure that this PR introduced a bug. If I understand correctly FWIW: Postgres: DuckDB: DuckDB v1.3.2 (Ossivalis) 0b83e5d2f6
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
D create table t1 AS (select 1 as a, 2 as b);
D insert into t1 values (1, 2);
D select from t1;
Parser Error:
SELECT clause without selection list
D from t1;
┌───────┬───────┐
│ a │ b │
│ int32 │ int32 │
├───────┼───────┤
│ 1 │ 2 │
│ 1 │ 2 │
└───────┴───────┘ |
|
So maybe the answer is that we should make |
I think we should be consistent with other databases This proposal seems reasonable to me SHould we also make |
DuckDB does support |
* Add failing test * Fix regression in SELECT FROM syntax with WHERE clause When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR #17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes #17513 * Revert * Fix regression: SELECT FROM syntax should return empty projection Removes automatic wildcard projection for empty projections, fixing the regression where `SELECT FROM table` incorrectly returned all columns instead of empty projection. Note: This temporarily breaks FROM-first syntax. A proper fix would require distinguishing between `FROM table` and `SELECT FROM table` at the parser level. Fixes #17513 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * add a better regression test * remove comment * fmt * Update datafusion/sqllogictest/test_files/projection.slt Co-authored-by: Oleks V <comphead@users.noreply.github.com> * Update datafusion/core/tests/sql/select.rs Co-authored-by: Oleks V <comphead@users.noreply.github.com> * revert docs * fmt --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Oleks V <comphead@users.noreply.github.com>
* Add failing test * Fix regression in SELECT FROM syntax with WHERE clause When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR apache#17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes apache#17513 * Revert * Fix regression: SELECT FROM syntax should return empty projection Removes automatic wildcard projection for empty projections, fixing the regression where `SELECT FROM table` incorrectly returned all columns instead of empty projection. Note: This temporarily breaks FROM-first syntax. A proper fix would require distinguishing between `FROM table` and `SELECT FROM table` at the parser level. Fixes apache#17513 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * add a better regression test * remove comment * fmt * Update datafusion/sqllogictest/test_files/projection.slt Co-authored-by: Oleks V <comphead@users.noreply.github.com> * Update datafusion/core/tests/sql/select.rs Co-authored-by: Oleks V <comphead@users.noreply.github.com> * revert docs * fmt --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Oleks V <comphead@users.noreply.github.com>
* Add failing test * Fix regression in SELECT FROM syntax with WHERE clause When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR #17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes #17513 * Revert * Fix regression: SELECT FROM syntax should return empty projection Removes automatic wildcard projection for empty projections, fixing the regression where `SELECT FROM table` incorrectly returned all columns instead of empty projection. Note: This temporarily breaks FROM-first syntax. A proper fix would require distinguishing between `FROM table` and `SELECT FROM table` at the parser level. Fixes #17513 🤖 Generated with [Claude Code](https://claude.ai/code) * add a better regression test * remove comment * fmt * Update datafusion/sqllogictest/test_files/projection.slt * Update datafusion/core/tests/sql/select.rs * revert docs * fmt --------- Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Oleks V <comphead@users.noreply.github.com>
* Add failing test * Fix regression in SELECT FROM syntax with WHERE clause When using 'SELECT FROM table WHERE condition', the query should create an empty projection (no columns) while still filtering rows. This was broken by PR apache#17295 which added FROM-first syntax support. The issue was that both 'FROM table' and 'SELECT FROM table' resulted in empty projection lists, making them indistinguishable. The fix checks for the presence of a WHERE clause to differentiate: - 'FROM table' (no WHERE) -> add wildcard projection (all columns) - 'SELECT FROM table WHERE ...' -> keep empty projection Also updates the test expectation to correctly show the empty Projection node in the query plan. Fixes apache#17513 * Revert * Fix regression: SELECT FROM syntax should return empty projection Removes automatic wildcard projection for empty projections, fixing the regression where `SELECT FROM table` incorrectly returned all columns instead of empty projection. Note: This temporarily breaks FROM-first syntax. A proper fix would require distinguishing between `FROM table` and `SELECT FROM table` at the parser level. Fixes apache#17513 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * add a better regression test * remove comment * fmt * Update datafusion/sqllogictest/test_files/projection.slt Co-authored-by: Oleks V <comphead@users.noreply.github.com> * Update datafusion/core/tests/sql/select.rs Co-authored-by: Oleks V <comphead@users.noreply.github.com> * revert docs * fmt --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Oleks V <comphead@users.noreply.github.com>
Which issue does this PR close?
Rationale for this change
I noticed in #17278 that
fromwithout an explicit projection did not work.This should fix it.
The from-first syntax is also available in duckdb. See https://duckdb.org/docs/stable/sql/query_syntax/from.html#examples
What changes are included in this PR?
Are these changes tested?
Yes, added SLT test
Are there any user-facing changes?
FROM-first syntax without projection is now supported.