clickhouse-driver
clickhouse-driver copied to clipboard
Placeholders are not replaced with the actual values when using executemany
Describe the bug I've noticed the problem when I tried to use pandas to_sql method but was able to reproduce the problem with clickhouse driver only.
To Reproduce
Create the table CREATE TABLE dbg_test (foo String) ENGINE = Log;
Then:
from clickhouse_driver import connect
conn = connect('clickhouse+native://default:@localhost:9000/default')
cursor = conn.cursor()
cursor.executemany('insert into dbg_test (foo) values(%(foo_value)s)', [{'foo_value': 'bar'}, {'foo_value': 'bar2'}])
Expected behavior Two entries (bar, bar2) are inserted into the database.
Actual behavior DB::Exception: Cannot parse expression of type String here: %(foo_value)s).
Versions 0.1.3 python 3.6.9
You should not use placeholders after VALUES clause in INSERT queries. The brief explanation is available in docs.
This case should be documented.
We can chop the rest of string after VALUES clause. But I don't think this is good idea.
That's a pity, as I mentioned earlier I've encountered this problem when I tried to save pandas dataframe into CH. I don't have any control over the way pandas is passing params to the driver, so I guess I'll have to look for a workaround.
Perhaps you should raise an exception if someone is trying to use placeholders? I spent quite some time trying to understand while a routine operation on pandas dataframe causes an error.
I'll give it a try early next week.