Skip to content
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

JOIN should require ON condition #13486

Open
findepi opened this issue Nov 19, 2024 · 2 comments
Open

JOIN should require ON condition #13486

findepi opened this issue Nov 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@findepi
Copy link
Member

findepi commented Nov 19, 2024

Describe the bug

SELECT ... FROM l JOIN r is not a valid SQL query, the ON condition should not be optional

To Reproduce

DataFusion CLI v43.0.0
> SELECT * FROM (SELECT 1 AS id, 'Foo' AS name) l JOIN (SELECT 1 AS id, 'Bar' as name) r;
+----+------+----+------+
| id | name | id | name |
+----+------+----+------+
| 1  | Foo  | 1  | Bar  |
+----+------+----+------+
1 row(s) fetched.

Expected behavior

The query should be rejected, the ON condition be requiered. In fact, omitting it might be typo with dangerous consequences (expensive cross join).

Trino

trino> SELECT * FROM (SELECT 1 AS id, 'Foo' AS name) l JOIN (SELECT 1 AS id, 'Bar' as name) r;
Query 20241119_124051_00000_rykay failed: line 1:87: mismatched input '<EOF>'. Expecting: 'ON', 'USING'
SELECT * FROM (SELECT 1 AS id, 'Foo' AS name) l JOIN (SELECT 1 AS id, 'Bar' as name) r <EOF>

PostgresSQL

postgres=# SELECT * FROM (SELECT 1 AS id, 'Foo' AS name) l JOIN (SELECT 1 AS id, 'Bar' as name) r;
ERROR:  syntax error at or near ";"
LINE 1: ...id, 'Foo' AS name) l JOIN (SELECT 1 AS id, 'Bar' as name) r;

DuckDB

D SELECT * FROM (SELECT 1 AS id, 'Foo' AS name) l JOIN (SELECT 1 AS id, 'Bar' as name) r;
Parser Error: syntax error at or near ";"
LINE 1: ... JOIN (SELECT 1 AS id, 'Bar' as name) r;
                                                  ^

Additional context

No response

@findepi findepi added the bug Something isn't working label Nov 19, 2024
@Dandandan
Copy link
Contributor

The condition is also required in the SQL specification here (for qualified joins).
https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#join-specification
so I think this should be changed / fixed in sqlparser-rs.

@findepi
Copy link
Member Author

findepi commented Nov 20, 2024

Thanks @Dandandan for checking the SQL standard too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants