Skip to content

Optionally allow for queries to start with FROM, instead of with SELECT #5076

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

Merged
merged 1 commit into from
Oct 25, 2022

Conversation

Mytherin
Copy link
Collaborator

The following SQL queries are now valid:

-- SELECT clause is optional, SELECT * is implied (if not included)
FROM tbl;

-- first 5 rows of the table
FROM tbl LIMIT 5;

-- select comes right after the from, after that the query follows the usual order
FROM tbl SELECT SUM(col) GROUP BY grp;

@domoritz
Copy link
Contributor

In the last query, what happens with grp in the select? Is it implicit?

@Mytherin
Copy link
Collaborator Author

Ah no, it is equivalent to the query with SELECT in the front. You don’t need to mention all groups in the SELECT (although not doing so is nearly always a mistake, as it was here :))

@Mytherin Mytherin merged commit 616c246 into duckdb:master Oct 25, 2022
@djouallah
Copy link

got an error here
From'lineitem' sum(L_quantity) group by l_shipmode;
BinderException: Binder Error: column "L_quantity" must appear in the GROUP BY clause or be used in an aggregate function

@Mytherin
Copy link
Collaborator Author

Mytherin commented Oct 25, 2022

You are missing a SELECT:

From'lineitem' SELECT sum(L_quantity) group by l_shipmode;

Strangely enough, your query still passes our parser. It is equivalent to the following:

SELECT * FROM 'lineitem' AS sum(l_quantity) GROUP BY l_shipmode;

i.e. the sum is turned into a table alias.

@djouallah
Copy link

djouallah commented Oct 25, 2022

sorry, don't shoot at me :), can we get rid of select :)

@Mytherin
Copy link
Collaborator Author

That doesn't work because of ambiguities in the grammar (as your own query demonstrated).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants