from datetime import datetime from mbutils.snowflake import ID_Worker path = r"C:\Users\xiaoan\Desktop\执行结果30.txt" with open(path,mode='r',encoding="utf-8") as f: all_data = f.readlines() data = [one.split(',"') for one in all_data[1:]] all_insert_values = [] for one in data: id = ID_Worker() one = [i.strip('\n').strip('"') for i in one] if int(one[4]) == 1: one[5] = int(one[5])*-1 one[6] = int(one[6])*-1 one[7] = int(one[7])*-1 else: one[5] = int(one[5]) one[6] = int(one[6]) one[7] = int(one[7]) one_value = (id,one[0],one[1],f"{one[3]} 00:00:00",one[2],one[6],one[5],one[7],one[8],int(one[4]),f"{datetime.now().replace(microsecond=0)}","system",f"{datetime.now().replace(microsecond=0)}","system") all_insert_values.append(one_value) all_insert_values_str = ','.join(map(str, all_insert_values)) one_sql = """INSERT INTO `t_ebike_visual_merchant_divide_total_2022` (id,tenant_id,service_id,day_time,account_id,amount,split_amount,pay,count,bill_type,created_at,created_pin,updated_at,updated_pin) VALUES {};""".format(all_insert_values_str) print(one_sql)
标签:语句,insert,批量,int,datetime,values,data,id From: https://www.cnblogs.com/ramsey/p/16935231.html