from clickhouse_driver import Client
def clickhouse16():
  #clickhouse: id , 端口 , 用户名,密码
  return Client(host='192.168.10.16', port='8123', user='root', password='123456')

def save_clickhouse(table, all_data):
    sig = 0
    list1 = []
    for i in all_data:
        sig += 1
        list1.append(i)
        if sig == 10000:
            sig = 0
            click_client.execute("""insert into mysql_test.{} values""".format(table), list1)
            list1 = []
    if len(list1) > 0:
        click_client.execute("""insert into mysql_test.{} values""".format(table), list1)

 click_client=clickhouse16()

1.插入数据
click_client.execute("""insert into mysql_test.table_name values""", list1)

2.大量数据插入
save_clickhouse(table, all_data)

3.删除数据,这个删除操作一定要小心,clickhouse删除是按照区块删除的,若是删除亿级别数据,需要多次删除,不要一下删除,
数据百万级别的随意。
sql_del="""ALTER TABLE mysql_test.t_app_info_logo_temp delete where 1=1;"""
click_client.execute(sql_del)

4.选出数据并插入另一张表,now_time是个变量
sql="""
insert into mysql_test.r_app_rank(id,cate_id,now_time)
with addHours(now(),8) as now_time
select id,cate_id,now_time from mysql_test.s_app_apppkg
"""
click_client.execute(sql)