自建库查询
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

from clickhouse_driver import Client
# 连接到ClickHouse
client = Client(
host='192.168.31.74',
port=9000,
user='default',
password='zhicheng123*',
database='mini_check'
)
# 2. 使用新数据库
client.execute('USE mini_check')
# 3. 创建简单的表
# create_table_sql = """
# CREATE TABLE IF NOT EXISTS user_table (
# user_uuid String,
# file_path String,
# is_delete UInt32,
# ) ENGINE = MergeTree()
# """
# create_table_sql = """
# CREATE TABLE IF NOT EXISTS user_table (
# user_uuid String,
# file_path String,
# is_delete UInt32,
# ) ENGINE = MergeTree()
# ORDER BY (user_uuid) -- 必须指定 ORDER BY
# SETTINGS index_granularity = 8192;
# """
#
# client.execute(create_table_sql)
#
# 4. 插入数据
data = [
("113", '/home/zyp/mnt/8T_disk/program/docx_deal/deal_finish_txt/2023-04-08/14397246.txt', 1),
("113", '/home/zyp/mnt/8T_disk/program/docx_deal/deal_finish_txt/2023-04-08/14397314.txt', 1),
("113", '/home/zyp/mnt/8T_disk/program/docx_deal/deal_finish_txt/2023-04-08/14397321.txt', 1)
]
client.execute('INSERT INTO user_table (user_uuid, file_path, is_delete) VALUES', data)
#
# 5. 查询数据
result = client.query_dataframe('SELECT * FROM user_table')
print(result)