clickhouse之python操作(python连接clickhouse)

网友投稿 683 2022-09-01


clickhouse之python操作(python连接clickhouse)

官网:​​install clickhouse-driver

1.clickhouse-driver (​​mymarilyn/clickhouse-driver: ClickHouse Python Driver with native interface support (github.com)​​)

纯客户端:

>>> from clickhouse_driver import Client>>>>>> client = Client('localhost')>>>>>> client.execute('SHOW TABLES')[('test',)]>>> client.execute('DROP TABLE IF EXISTS test')[]>>> client.execute('CREATE TABLE test (x Int32) ENGINE = Memory')[]>>> client.execute(... 'INSERT INTO test (x) VALUES',... [{'x': 100}]... )1>>> client.execute('INSERT INTO test (x) VALUES', [[200]])1>>> client.execute(... 'INSERT INTO test (x) '... 'SELECT * FROM system.numbers LIMIT %(limit)s',... {'limit': 3}... )[]>>> client.execute('SELECT sum(x) FROM test')[(303,)]

使用数据库接口:

>>> from clickhouse_driver import connect>>>>>> conn = connect('clickhouse://localhost')>>> cursor = conn.cursor()>>>>>> cursor.execute('SHOW TABLES')>>> cursor.fetchall()[('test',)]>>> cursor.execute('DROP TABLE IF EXISTS test')>>> cursor.fetchall()[]>>> cursor.execute('CREATE TABLE test (x Int32) ENGINE = Memory')>>> cursor.fetchall()[]>>> cursor.executemany(... 'INSERT INTO test (x) VALUES',... [{'x': 100}]... )>>> cursor.rowcount1>>> cursor.executemany('INSERT INTO test (x) VALUES', [[200]])>>> cursor.rowcount1>>> cursor.execute(... 'INSERT INTO test (x) '... 'SELECT * FROM system.numbers LIMIT %(limit)s',... {'limit': 3}... )>>> cursor.rowcount0>>> cursor.execute('SELECT sum(x) FROM test')>>> cursor.fetchall()[(303,)]

链接的使用使用的参数:

host: 地址

port: 端口

user: 用户名

password: 密码

database: 数据库名称

send_receive_timeout: 超时时间


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java实现简单点餐系统
下一篇:python之数据库管理工具sandman2(python数据管理系统)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~