Python将数据写入ClickHouse
原创
©著作权归作者所有:来自51CTO博客作者周成乐的原创作品,请联系作者获取转载授权,否则将追究法律责任
from clickhouse_driver import Client
# connect ClickHouse
client = Client(host= ,port= ,user= ,database= , password=)
# 得到table1中查询的数据导入table2中(database2中应该事先建立对应的table2表)
query_ck_sql = """ SELECT *
FROM database1.table1
WHERE date = today() """
# 导入数据到临时表
try:
# 导入数据
client.execute("insert into {official_table_db}.{official_all_table_name} \
{query_ck_sql}".format(
official_table_db = database2,
official_table_name = table2,
query_ck_sql = query_ck_sql)
,types_check = True)
except Exception as e:
print str(e)