Python將資料寫入ClickHouse
阿新 • • 發佈:2018-12-19
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 e