使用 clickhouse_driver 写入 时间戳时 失败 ,单独执行sql 能成功 ,没找到原因
我在用clickhouse_driver 写入数据时 抛错, 通过DBeaver工具 执行sql 能成功!错误重点信息如下,目前能定位到就是 timestamp
Int64字段写入问题,但是值和类型没排查除问题?很疑惑?
clickhouse_driver.errors.ServerException: Code: 62.
DB::Exception: Cannot parse expression of type Int64 here: ?, ?, ?, ?, ?, ?): While executing ValuesBlockInputFormat. Stack trace:
数据结构
CREATE TABLE okx_db.file_usdt
(
`timestamp` Int64,
`open` Float64,
`high` Float64,
`low` Float64,
`close` Float64,
`volume` Float64
)
ENGINE = MergeTree
PRIMARY KEY timestamp
ORDER BY timestamp
SETTINGS index_granularity = 8192;
通过DBeaver工具 执行sql 能成功
INSERT INTO okx_db.file_usdt (timestamp, open, high, low, close, volume) VALUES (1691317560000, 4.156, 4.157, 4.154, 4.154, 417.56113);
python 代码
import clickhouse_driver
conn = clickhouse_driver.connect(host='127.0.0.1', port=19000, user='default', password='', database='okx_db')
query = 'INSERT INTO okx_db.file_usdt (timestamp, open, high, low, close, volume) VALUES (?, ?, ?, ?, ?, ?)'
values = [(1691317560000, 4.149, 4.149, 4.147, 4.147, 417.56113)]
cursor = conn.cursor()
for value in values:
cursor.execute(query, value)
conn.commit()
cursor.close()
sql ? 和值绑定的问题。 这样就可以正常写入。