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

Crash during an oracle query parsing. The query is working fine when running on the DB. #3231

Closed
Hal-H2Apps opened this issue Mar 27, 2024 · 4 comments
Assignees

Comments

@Hal-H2Apps
Copy link

sqlglot version: 23.2.0

Fully reproducible code snippet

import sqlglot

sql = sqlglot.parse_one(sql="""SELECT 1
FROM T0 G_T0
INNER JOIN T1 G_T1
INNER JOIN T2 G_T2 ON G_T1.ID1 = G_T2.ID2
LEFT JOIN T3 G_T3 ON G_T1.ID_O = G_T3.ID_O
ON G_T1.ID_N = G_T0.ID_N""", read='oracle')

Official Documentation
Please include links to official SQL documentation related to your issue.

Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
coro = func()
^^^^^^
File "", line 1, in
File "/usr/local/lib/python3.11/site-packages/sqlglot/init.py", line 124, in parse_one
result = dialect.parse(sql, **opts)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlglot/dialects/dialect.py", line 490, in parse
return self.parser(**opts).parse(self.tokenize(sql), sql)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlglot/parser.py", line 1163, in parse
return self._parse(
^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlglot/parser.py", line 1232, in _parse
self.raise_error("Invalid expression / Unexpected token")
File "/usr/local/lib/python3.11/site-packages/sqlglot/parser.py", line 1273, in raise_error
raise error
sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 6, Col: 3.
NER JOIN T2 G_T2 ON G_T1.ID1 = G_T2.ID2
LEFT JOIN T3 G_T3 ON G_T1.ID_O = G_T3.ID_O
ON G_T1.ID_N = G_T0.ID_N

@georgesittas
Copy link
Collaborator

I suppose the final ON clause binds to the first inner join?

@Hal-H2Apps
Copy link
Author

I suppose the final ON clause binds to the first inner join?

Yes, indeed.

@georgesittas
Copy link
Collaborator

Thanks, we'll take a look soon. If you need a short-term workaround I believe you can simply move that condition so it's next to the join instead of it being at the end of the query.

@Hal-H2Apps
Copy link
Author

Thank you.
Sadly I'm not able to modify queries. I'm reading them and analyse them by batches.

sqlglot is wonderful for that. Thank you so much!

@VaggelisD VaggelisD self-assigned this Mar 27, 2024
@tobymao tobymao assigned tobymao and unassigned VaggelisD Mar 28, 2024
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

No branches or pull requests

4 participants