How to handle apostrophe in an INSERT statement when inserting into Clickhouse using Python?

72 Views Asked by At

I am inserting into Clickhouse but an error occurs because of the apostrophe in the statement.

tmp_list = ['A\'BCD','12345','1a2a3a4a']

insert = f'INSERT INTO tmp_table (NAME) VALUES (\'{tmp_list[0]}\', \'{tmp_list[1]}\', \'{tmp_list[2]}\')'
client.execute(insert)

Output

ServerException: Code: 47. DB::Exception: Missing columns: 'A'BCD' while processing query: 'A'BCD', required columns: 'A'BCD' 'A'BCD' : While executing ValuesBlockInputFormat.

tmp_list = ['A\'BCD','12345','1a2a3a4a']

insert = f'INSERT INTO tmp_table (NAME) VALUES ({repr(tmp_list[0])}, {repr(tmp_list[1])},{repr(tmp_list[2])})'
client.execute(insert)

Output

ServerException: Code: 47. DB::Exception: Missing columns: 'A'BCD' while processing query: 'A'BCD', required columns: 'A'BCD' 'A'BCD' : While executing ValuesBlockInputFormat.

0

There are 0 best solutions below