from clickhouse_driver import Client,connect
from datetime import datetime,timedelta

connection = connect(host='10.9.0.81', port=9001, user='xxx', password='xxx', database='xxx')
# 循环打印近30天的日期
for i in range(1,31):
    date = (datetime.now() - timedelta(days=i)).strftime('%Y-%m-%d')
    date2 = date + ' 00:00:00'
    insert_sql = '''
    INSERT INTO dwd_station_connect (station_id,region_id,region_name,line_num,line_name,regist_time,last_time,valid,stat,ip_address,date_time,fep_ip_address) VALUES (11301006,1,'2222',1,NULL,'2024-07-04 12:23:34','2024-06-04 20:32:18',0,1,'10.141.13.246','%s','10.14.101.32')
                 ''' % date2
    print(insert_sql)
    # 执行插入语句
    with connection.cursor() as cursor:
        cursor.execute(insert_sql)

# 关闭客户端连接
connection.close()
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐