每次insert太麻烦了
先在clickhosue中建表 test_user表
CREATE TABLE dwh.test_user
(
name String,
age Int32,
address String,
phone String,
email String
) ENGINE = MergeTree()
ORDER BY name;
此时表中暂无数据
用Python脚本来造一些数据
from faker import Faker
from clickhouse_driver import Client
# 创建fake实例
fake = Faker('zh_CN')
# 连接clickhouse数据库
client = Client(host='xxxx',user='xxx',password='xxxx')
# 定义插入语句
insert_query = "INSERT INTO dwh.test_user (name, age, address, phone, email) VALUES"
# 生成数据并执行
data = [(fake.name(), fake.random_int(min=0, max=100), fake.address().replace('\n', ', '), fake.phone_number(), fake.email()) for _ in range(100)]
client.execute(insert_query, data)
print("Data insertion complete.")
# 关闭连接
client.disconnect()
此时数据已写入表中