-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
std/parsesql: Fix JOIN parsing #22890
Conversation
It should still be optional and "JOIN" is a shortcut for "INNER JOIN" for backwards compatibility. |
@Araq wrote:
Sorry, but I have not understood your message without logical parentheses in place. |
I mean that
should continue to work and the JOIN should continue to mean INNER JOIN. If that's what your PR does, it's fine. |
@Araq Yes, this example is still parsed (and the corresponding test is kept as it is), what has changed, though, is its tree representation: earlier it was
now it is:
|
Huh, sorry, that is not good, it's a breaking change of the worst kind, hidden and secret, only detected at runtime. Also, the old AST version makes more sense to me. |
The module documentation claims:
PostgreSQL SELECT documentation: https://www.postgresql.org/docs/current/sql-select.html JOIN is a part of the FROM clause, both syntactically and semantically. Aiming for backwards compatibility as the highest priority did not make sense to me. The API is declared unstable. Ok, if we try to keep the compatibility, how do you parse the following: SELECT a.id
FROM a, b JOIN c ON b.id = c.id, d In the solution proposed, it would produce the tree:
Although semantically Also, I doubt that any significant amount of code did depend on the current JOIN tree representation, as the current code can't parse the simplest statements: SELECT * FROM a LEFT JOIN b ON a.id = b.id;
SELECT * FROM a JOIN b ON a.id = b.id WHERE true;
SELECT * FROM a JOIN b ON a.id = b.id ORDER BY 1;
SELECT * FROM a JOIN b ON a.id = b.id, c;
SELECT * FROM a JOIN b ON a.id = b.id JOIN c ON b.id = c.id; The breaking change can be documented in the release notes. |
I have just added support for parenthesized JOIN subexpressions, such as: SELECT id
FROM
a JOIN (b JOIN c ON b.id = c.id) ON a.id = b.id I did not plan to do it within this PR, but it should be there for the completeness. |
df605a3
to
5d7b53a
Compare
This pull request is stale because it has been open for 1 year with no activity. Contribute more commits on the pull request and rebase it on the latest devel, or it will be closed in 30 days. Thank you for your contributions. |
5d7b53a
to
d7190f5
Compare
Rebased on the latest devel, although it seems no one else wants this to be working. |
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
This commit fixes/adds tests for and fixes several issues with `JOIN` operator parsing: - For OUTER joins, LEFT | RIGHT | FULL specifier is not optional ```nim doAssertRaises(SqlParseError): discard parseSql(""" SELECT id FROM a OUTER JOIN b ON a.id = b.id """) ``` - For NATURAL JOIN and CROSS JOIN, ON and USING clauses are forbidden ```nim doAssertRaises(SqlParseError): discard parseSql(""" SELECT id FROM a CROSS JOIN b ON a.id = b.id """) ``` - JOIN should parse as part of FROM, not after WHERE ```nim doAssertRaises(SqlParseError): discard parseSql(""" SELECT id FROM a WHERE a.id IS NOT NULL INNER JOIN b ON a.id = b.id """) ``` - LEFT JOIN should parse ```nim doAssert $parseSql(""" SELECT id FROM a LEFT JOIN b ON a.id = b.id """) == "select id from a left join b on a.id = b.id;" ``` - NATURAL JOIN should parse ```nim doAssert $parseSql(""" SELECT id FROM a NATURAL JOIN b """) == "select id from a natural join b;" ``` - USING should parse ```nim doAssert $parseSql(""" SELECT id FROM a JOIN b USING (id) """) == "select id from a join b using (id );" ``` - Multiple JOINs should parse ```nim doAssert $parseSql(""" SELECT id FROM a JOIN b ON a.id = b.id LEFT JOIN c USING (id) """) == "select id from a join b on a.id = b.id left join c using (id );" ``` (cherry picked from commit 46bb47a)
This commit fixes/adds tests for and fixes several issues with
JOIN
operator parsing: