Open IterableTrucks opened 3 years ago
I've noticed there were multiple issues already solving this issue for individual keywords (e.g. https://github.com/andialbrecht/sqlparse/issues/507, https://github.com/andialbrecht/sqlparse/issues/446), closed by extending this list of keywords: https://github.com/andialbrecht/sqlparse/blob/3bc7d93254cbef71bdef91905f1814201a1b1f02/sqlparse/keywords.py#L52
I found this issue while searching for a reason why Querybook, which uses sqlparse
, is detecting UNNEST
as a table name in e.g. Presto query ...CROSS JOIN UNNEST(t.id)...
. The reason is UNNEST
is detected as tokens.Name
instead of tokens.Keyword
, because it's followed by parenthesis = exactly the same issue as it the mentioned closed issue.
So I think there are two options:
JOIN
and UNNEST
🙏 keywords(r'[A-ZÀ-Ü]\w*(?=\()', tokens.Name)
with (r'[A-ZÀ-Ü]\w*(?=\()', is_keyword)
here https://github.com/andialbrecht/sqlparse/blob/3bc7d93254cbef71bdef91905f1814201a1b1f02/sqlparse/keywords.py#L63 but then some tests were broken, because sqlparse.sql.Function
wasn't detected correctly for keywords, that were handled as names before, and therefore calling get_parameters()
method of sql.Function
is failing/missing.
Then it got more complicated with the grouping functions and I didn't find any good way how to fix it without breaking any unit test, yet.
But seemed like correct idea in the beginning... What do you think @andialbrecht ?
Adding to the list WHERE x = ANY(...)
, where ANY
is a keyword, not a function.
Parsing a sql with parenthesis right after keyword without any whitespace characters (which is syntactically correct in SQL standard) will produce the belowing unexpected result:
Compared with the correct result adding a whitespace after JOIN: