@@ -21,29 +21,20 @@ def path_str_to_parts(path_str: str):
2121 return parts , is_quoted
2222
2323
24- RESERVED_KEYWORDS = {
25- 'PERSIST' , 'IF' , 'EXISTS' , 'NULLS' , 'FIRST' , 'LAST' ,
26- 'ORDER' , 'BY' , 'GROUP' , 'PARTITION'
24+ # Here is a hardcoded set of keywords that can be used as identifiers without escaping.
25+ # For example, in a query like this: select {keyword} from tbl
26+ # If there is a need to update this list, an example code to retrieve all keywords can be found here in v0.13.6
27+ keywords_to_escape = {
28+ "VALUES" , "DESCRIBE" , "THEN" , "WRITE" , "WITH" , "INSERT" , "DROP" , "CROSS" ,
29+ "SET" , "ASC" , "IS" , "IN" , "NOT" , "INTO" , "WINDOW" , "ALTER" , "WHERE" ,
30+ "DISTINCT" , "USE" , "INNER" , "COLLATE" , "FOR" , "USING" , "FULL" , "LIKE" ,
31+ "JOIN" , "SELECT" , "OVER" , "CASE" , "LIMIT" , "END" , "UNION" , "DELETE" ,
32+ "HAVING" , "OUTER" , "FROM" , "AS" , "CHARACTER" , "INTERSECT" , "CONVERT" ,
33+ "WHEN" , "OR" , "AND" , "UPDATE" , "BETWEEN" , "DESC" , "EXPLAIN" , "SHOW" ,
34+ "EXCEPT" , "LEFT" , "ELSE" , "READ" , "RIGHT"
2735}
2836
2937
30- _reserved_keywords : set [str ] = None
31-
32-
33- def get_reserved_words () -> set [str ]:
34- global _reserved_keywords
35-
36- if _reserved_keywords is None :
37- from mindsdb_sql_parser .lexer import MindsDBLexer
38-
39- _reserved_keywords = RESERVED_KEYWORDS
40- for word in MindsDBLexer .tokens :
41- if '_' not in word :
42- # exclude combinations
43- _reserved_keywords .add (word )
44- return _reserved_keywords
45-
46-
4738class Identifier (ASTNode ):
4839 def __init__ (
4940 self , path_str = None , parts = None , is_outer = False , with_rollup = False ,
@@ -77,15 +68,14 @@ def append(self, other: "Identifier") -> None:
7768 self .is_quoted += other .is_quoted
7869
7970 def iter_parts_str (self ):
80- reserved_words = get_reserved_words ()
8171 for part , is_quoted in zip (self .parts , self .is_quoted ):
8272 if isinstance (part , Star ):
8373 part = str (part )
8474 else :
8575 if (
8676 is_quoted
8777 or not no_wrap_identifier_regex .fullmatch (part )
88- or part .upper () in reserved_words
78+ or part .upper () in keywords_to_escape
8979 ):
9080 part = f'`{ part } `'
9181 yield part
0 commit comments