C

chdb-sql

by @clickhousev
4.4(120)

此技能让你在 Python 进程中直接运行 ClickHouse SQL,无需安装服务器。可查询本地文件、远程数据库和云存储,支持多源数据联合分析,极大简化数据探索与 ETL 流程,提升数据分析效率。

sqlclickhousedata-analysispythondatabaseGitHub
安装方式
npx skills add https://github.com/clickhouse/agent-skills --skill chdb-sql
compare_arrows

Before / After 效果对比

1
使用前

用户需要搭建 ClickHouse 服务器或使用其他工具,手动导入数据,编写复杂脚本,整个过程耗时且容易出错,平均每次数据分析耗时 60 分钟。

使用后

此技能直接在 Python 中运行 SQL,无需服务器,查询本地文件和数据库,平均 10 分钟即可完成相同分析,且无需维护基础设施。

SKILL.md

chdb SQL — ClickHouse in Your Python Process

Run ClickHouse SQL directly in Python — no server needed. Query local files, remote databases, and cloud storage with full ClickHouse SQL power.

pip install chdb

Decision Tree: Pick the Right API

1. One-off query on files or databases → chdb.query()
2. Multi-step analysis with tables      → Session
3. DB-API 2.0 connection                → chdb.connect()
4. Pandas-style DataFrame operations    → Use chdb-datastore skill instead

chdb.query() — One Line, Any Data

import chdb

chdb.query("SELECT * FROM file('data.parquet', Parquet) WHERE price > 100 LIMIT 10")       # local files
chdb.query("SELECT * FROM mysql('db:3306', 'shop', 'orders', 'root', 'pass')")              # databases
chdb.query("SELECT * FROM s3('s3://bucket/data.parquet', NOSIGN) LIMIT 10")                 # cloud storage
chdb.query("SELECT * FROM deltaLake('s3://bucket/delta/table', NOSIGN) LIMIT 10")           # data lakes

# Cross-source join
chdb.query("""
    SELECT u.name, o.amount FROM mysql('db:3306', 'crm', 'users', 'root', 'pass') AS u
    JOIN file('orders.parquet', Parquet) AS o ON u.id = o.user_id ORDER BY o.amount DESC
""")

data = {"name": ["Alice", "Bob"], "score": [95, 87]}
chdb.query("SELECT * FROM Python(data) ORDER BY score DESC")                                # Python data
df = chdb.query("SELECT * FROM numbers(10)", "DataFrame")                                   # output formats
chdb.query("SELECT toDate({d:String}) + number FROM numbers({n:UInt64})",
    "DataFrame", params={"d": "2025-01-01", "n": 30})                                      # parametrized

Table functions → table-functions.md | SQL functions → sql-functions.md | Full API → api-reference.md

Session — Stateful Analysis Pipelines

from chdb import session as chs
sess = chs.Session("./analytics_db")   # persistent; Session() for in-memory

sess.query("CREATE TABLE users ENGINE=MergeTree() ORDER BY id AS SELECT * FROM mysql('db:3306','crm','users','root','pass')")
sess.query("CREATE TABLE events ENGINE=MergeTree() ORDER BY (ts,user_id) AS SELECT * FROM s3('s3://logs/events/*.parquet',NOSIGN)")
sess.query("""
    SELECT u.country, count() AS cnt, uniqExact(e.user_id) AS users
    FROM events e JOIN users u ON e.user_id = u.id
    WHERE e.ts >= today() - 7 GROUP BY u.country ORDER BY cnt DESC
""", "Pretty").show()
sess.close()

Connection API (DB-API 2.0)

from chdb import dbapi
conn = dbapi.connect()
cur = conn.cursor()
cur.execute("SELECT * FROM file('data.parquet', Parquet) WHERE value > 100")
print(cur.fetchall())
cur.close()
conn.close()

Troubleshooting

ProblemFix
ImportError: No module named 'chdb'pip install chdb
DB::Exception: FILE_NOT_FOUNDCheck file path; use absolute path or verify cwd
DB::Exception: Unknown table functionCheck function name spelling (e.g., deltaLake not deltalake)
Connection refused to remote DBCheck host:port format; ensure remote DB allows connections
Environment checkRun python scripts/verify_install.py (from skill directory)

References

Note: This skill teaches how to use chdb SQL. For pandas-style operations, use the chdb-datastore skill. For contributing to chdb source code, see CLAUDE.md in the project root.


chdb SQL

Agent skill for using chdb's SQL API — run ClickHouse SQL directly in Python without a server.

Installation

npx skills add clickhouse/agent-skills

What's Included

FilePurpose
SKILL.mdSkill definition with quick-start examples
references/api-reference.mdchdb.query(), Session, Connection signatures
references/table-functions.mdAll ClickHouse table functions (file, s3, mysql, etc.)
references/sql-functions.mdCommonly used ClickHouse SQL functions
examples/examples.md9 runnable examples with expected output
scripts/verify_install.pyEnvironment verification script

Trigger Phrases

This skill activates when you:

  • "Query this Parquet/CSV file with SQL"
  • "Use chdb to run a query"
  • "Join MySQL and S3 data with SQL"
  • "Create a ClickHouse session"
  • "Use ClickHouse table functions"
  • "Write a parametrized query"

Related

  • chdb-datastore — For pandas-style DataFrame operations, use the chdb-datastore skill instead
  • clickhouse-best-practices — For ClickHouse schema/query optimization

Documentation

用户评价 (0)

发表评价

效果
易用性
文档
兼容性

暂无评价

统计数据

安装量5.0K
评分4.4 / 5.0
版本
更新日期2026年8月1日
对比案例1 组

用户评分

4.4(120)
5
37%
4
43%
3
13%
2
5%
1
2%

为此 Skill 评分

0.0

兼容平台

🤖claude-code

时间线

创建2026年7月26日
最后更新2026年8月1日
🎁 Agent 知识卡片
调研问卷