clickhouse_driver用法
时间: 2023-12-08 19:06:16 浏览: 170
clickhouse-driver:用于ClickHouse列式数据库的Golang驱动程序
5星 · 资源好评率100%
以下是clickhouse_driver的用法示例:
1. 连接到ClickHouse服务器并执行查询:
```python
from clickhouse_driver import Client
client = Client('localhost')
result = client.execute('SELECT * FROM my_table')
print(result)
```
2. 执行带有参数的查询:
```python
from clickhouse_driver import Client
client = Client('localhost')
result = client.execute('SELECT * FROM my_table WHERE id = %(id)s', {'id': 1})
print(result)
```
3. 执行批量插入:
```python
from clickhouse_driver import Client
client = Client('localhost')
data = [('John', 25), ('Ann', 30), ('Peter', 35)]
client.execute('INSERT INTO my_table (name, age) VALUES', data)
```
4. 执行带有参数的批量插入:
```python
from clickhouse_driver import Client
client = Client('localhost')
data = [{'name': 'John', 'age': 25}, {'name': 'Ann', 'age': 30}, {'name': 'Peter', 'age': 35}]
client.execute('INSERT INTO my_table (name, age) VALUES', data)
```
阅读全文