1414
1515
1616CREATE_TABLE_QUERY = '''
17- CREATE TABLE {if_not_exists} {db_name}. {table_name}
17+ CREATE TABLE {if_not_exists} ` {db_name}`.` {table_name}`
1818(
1919{fields},
2020 `_version` UInt64,
2626'''
2727
2828DELETE_QUERY = '''
29- DELETE FROM {db_name}. {table_name} WHERE ({field_name}) IN ({field_values})
29+ DELETE FROM ` {db_name}`.` {table_name}` WHERE ({field_name}) IN ({field_values})
3030'''
3131
3232
@@ -126,8 +126,8 @@ def execute_command(self, query):
126126 time .sleep (ClickhouseApi .RETRY_INTERVAL )
127127
128128 def recreate_database (self ):
129- self .execute_command (f'DROP DATABASE IF EXISTS { self .database } ' )
130- self .execute_command (f'CREATE DATABASE { self .database } ' )
129+ self .execute_command (f'DROP DATABASE IF EXISTS ` { self .database } ` ' )
130+ self .execute_command (f'CREATE DATABASE ` { self .database } ` ' )
131131
132132 def get_last_used_version (self , table_name ):
133133 return self .tables_last_record_version .get (table_name , 0 )
@@ -210,9 +210,9 @@ def insert(self, table_name, records, table_structure: TableStructure = None):
210210 records_to_insert .append (tuple (record ) + (current_version ,))
211211 current_version += 1
212212
213- full_table_name = table_name
213+ full_table_name = f'` table_name`'
214214 if '.' not in full_table_name :
215- full_table_name = f'{ self .database } . { table_name } '
215+ full_table_name = f'` { self .database } `.` { table_name } ` '
216216
217217 duration = 0.0
218218 for attempt in range (ClickhouseApi .MAX_RETRIES ):
@@ -258,10 +258,10 @@ def erase(self, table_name, field_name, field_values):
258258 )
259259
260260 def drop_database (self , db_name ):
261- self .execute_command (f'DROP DATABASE IF EXISTS { db_name } ' )
261+ self .execute_command (f'DROP DATABASE IF EXISTS ` { db_name } ` ' )
262262
263263 def create_database (self , db_name ):
264- self .cursor .execute (f'CREATE DATABASE { db_name } ' )
264+ self .cursor .execute (f'CREATE DATABASE ` { db_name } ` ' )
265265
266266 def select (self , table_name , where = None , final = None ):
267267 query = f'SELECT * FROM { table_name } '
@@ -282,7 +282,7 @@ def query(self, query: str):
282282 return self .client .query (query )
283283
284284 def show_create_table (self , table_name ):
285- return self .client .query (f'SHOW CREATE TABLE { table_name } ' ).result_rows [0 ][0 ]
285+ return self .client .query (f'SHOW CREATE TABLE ` { table_name } ` ' ).result_rows [0 ][0 ]
286286
287287 def get_system_setting (self , name ):
288288 results = self .select ('system.settings' , f"name = '{ name } '" )
0 commit comments