(作者:陈玓玏)
使用clickhouse-driver包,先通过pip install clickhouse-driver安装包,再通过以下代码执行sql。
from clickhouse_driver import Client
client = Client(host='10.43.234.214', port=9000, user='clickhouse', password='c1ickh0use0perator')
# 执行一个创建数据库的语句
#query = 'create table cdl'
#result = client.execute(query)
# 执行一个创建表的语句
query = '''CREATE TABLE IF NOT EXISTS cdl.star
(
week Int32,
star Int32
)ENGINE = MergeTree()
ORDER BY week
PARTITION 服务器托管网BY week
PRIMARY KEY week'''
result = client.execute(query)
data = [
{'week': 1, 'star': 1},
{'week': 2, 'star': 10},
{'week': 3, 'star': 100},
{'week服务器托管网': 4, 'star': 300},
{'week': 5, 'star': 500},
{'week': 6, 'star': 1000}
]
#执行插入语句
query = "INSERT INTO cdl.star VALUES" + ','.join(["(%s,%s)" % (d['week'], d['star']) for d in data])
result = client.execute(query)
#执行查询
query = 'select * from cdl.star limit 10'
result = client.execute(query)
# 打印结果
for row in result:
print(row)
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
相关推荐: HarmonyOS—@State装饰器:组件内状态
@State装饰的变量,或称为状态变量,一旦变量拥有了状态属性,就和自定义组件的渲染绑定起来。当状态改变时,UI会发生对应的渲染改变。 在状态变量相关装饰器中,@State是最基础的,使变量拥有状态属性的装饰器,它也是大部分状态变量的数据源。 说明 从API …