# Chdb Sql > Use when the user wants to run SQL — especially analytical SQL — on local files (parquet/csv/json), URLs, S3 paths, or remote databases (Postgres, MySQL, MongoDB, ClickHouse Cloud, Iceberg, Delta Lake) without setting up a server. Provides chDB — embedded ClickHouse SQL in Python with 1000+ functions, Session for stateful multi-step pipelines, parametrized queries, and cross-source joins via `s3()`, `mysql()`, `postgresql()`, `iceberg()`, `deltaLake()`, `remoteSecure()` table functions. TRIGGER when: user wants SQL on parquet/csv/files or across remote analytical sources; uses ClickHouse SQL features (window functions, windowFunnel, geoToH3, JSON path ops, Session, parametrized queries); imports `chdb` or calls `chdb.query()`. SKIP this skill for pandas-style DataFrame method-chaining (use chdb-datastore instead) or ClickHouse server administration. Fuente: https://skillsagentes.com/skills/clickhouse/agent-skills/chdb-sql Markdown: https://skillsagentes.com/skills/clickhouse/agent-skills/chdb-sql.md Repositorio: https://github.com/ClickHouse/agent-skills Autor: ClickHouse Licencia: Apache-2.0 Actualizado: hace 3 meses Coste de contexto: 217 tok instalada, 1.2k tok al activarse, 10.2k tok con todos los archivos del bundle Bundle: 8 archivos, 40 KB Permisos que pide: ninguno declarado ## Instalación Un skill son archivos markdown: los mismos archivos valen para cualquier agente y lo único que cambia es el directorio de destino, es decir la bandera `--agent`. Añade `-g` para instalarlo en todos los proyectos de la máquina. ```bash # Claude Code npx -y skills add ClickHouse/agent-skills --skill chdb-sql --agent claude-code # Cursor npx -y skills add ClickHouse/agent-skills --skill chdb-sql --agent cursor # Codex npx -y skills add ClickHouse/agent-skills --skill chdb-sql --agent codex # Gemini CLI npx -y skills add ClickHouse/agent-skills --skill chdb-sql --agent gemini # Windsurf npx -y skills add ClickHouse/agent-skills --skill chdb-sql --agent windsurf # Cline npx -y skills add ClickHouse/agent-skills --skill chdb-sql --agent cline ``` ## Antes de instalar - Necesita en el PATH: pip ## Archivos - README.md — 1 KB - SKILL.md — 5 KB - examples/examples.md — 9 KB - metadata.json — 451 B - references/api-reference.md — 6 KB - references/sql-functions.md — 10 KB - references/table-functions.md — 5 KB - scripts/verify_install.py — 3 KB ## SKILL.md Reproducido tal cual desde ClickHouse/agent-skills bajo Apache-2.0. Esta sección es el documento original y está en inglés. # 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. ```bash 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 ```python 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](references/table-functions.md) | SQL functions → [sql-functions.md](references/sql-functions.md) | Full API → [api-reference.md](references/api-reference.md) ## Session — Stateful Analysis Pipelines ```python 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) ```python 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 | Problem | Fix | |---------|-----| | `ImportError: No module named 'chdb'` | `pip install chdb` | | `DB::Exception: FILE_NOT_FOUND` | Check file path; use absolute path or verify cwd | | `DB::Exception: Unknown table function` | Check function name spelling (e.g., `deltaLake` not `deltalake`) | | Connection refused to remote DB | Check host:port format; ensure remote DB allows connections | | Environment check | Run `python scripts/verify_install.py` (from skill directory) | ## References - [API Reference](references/api-reference.md) — query/Session/connect signatures - [Table Functions](references/table-functions.md) — All ClickHouse table functions - [SQL Functions](references/sql-functions.md) — Commonly used SQL functions - [Examples](examples/examples.md) — 9 runnable examples with expected output - [Official Docs](https://clickhouse.com/docs/chdb) > 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. ## Dónde encaja - Categoría: [Bases de datos](https://skillsagentes.com/categorias/bases-de-datos.md) — Diseño de esquemas, migraciones y optimización de consultas. - Creador: [ClickHouse](https://skillsagentes.com/creators/clickhouse.md) — 11 skills en el directorio - [Todas las skills](https://skillsagentes.com/skills.md) - [Ranking de instalaciones](https://skillsagentes.com/ranking.md) ## Otras skills del mismo repositorio - [Clickhouse Js Node Rowbinary](https://skillsagentes.com/skills/clickhouse/agent-skills/clickhouse-js-node-rowbinary.md): Generate TypeScript/JavaScript code that reads/decodes AND writes/encodes ClickHouse RowBinary streams for the ClickHouse HTTP server. Use this skill whenever a user wants to parse or produce `RowBinary`, `RowBinaryWithNames`, or `RowBinaryWithNamesAndTypes`. Node.js only, doesn't cover browsers. - [Infra Clickhouse](https://skillsagentes.com/skills/clickhouse/agent-skills/infra-clickhouse.md): Sets up and manages ClickHouse using the clickhousectl CLI — installs and runs a local ClickHouse server for development, and creates managed ClickHouse Cloud services for production (authentication, service creation, schema migration, application connection). Use when the user wants to build an application with ClickHouse, set up a local ClickHouse dev environment, create tables and start querying, deploy ClickHouse to production or ClickHouse Cloud, or migrate from a local setup to the cloud. - [Infra Postgres](https://skillsagentes.com/skills/clickhouse/agent-skills/infra-postgres.md): Sets up and manages Postgres using the clickhousectl CLI — runs a local Docker-backed Postgres for development, and creates and operates managed ClickHouse Cloud Postgres services (connections, TLS, runtime config, read replicas, failover, point-in-time restore). Use when the user wants a Postgres or PostgreSQL database for their application, a local Postgres dev environment, psql access, or a managed/production Postgres in ClickHouse Cloud, or mentions moving a local Postgres to production. - [Clickstack Otel Collector](https://skillsagentes.com/skills/clickhouse/agent-skills/clickstack-otel-collector.md): Use when a user wants to wire an OpenTelemetry collector into a Managed ClickStack service on ClickHouse Cloud, either by deploying a new local collector (Docker run or Docker Compose) or by configuring their own existing collector, then send rich synthetic telemetry and verify it is visible in ClickStack. - [Clickhouse Js Node Troubleshooting](https://skillsagentes.com/skills/clickhouse/agent-skills/clickhouse-js-node-troubleshooting.md): Troubleshoot and resolve common issues with the ClickHouse Node.js client (@clickhouse/client). Use this skill whenever a user reports errors, unexpected behavior, or configuration questions involving the Node.js client specifically — including socket hang-up errors, Keep-Alive problems, stream handling issues, data type mismatches, read-only user restrictions, proxy/TLS setup problems, or long-running query timeouts. Trigger even when the user hasn't precisely named the issue; vague symptoms like "my inserts keep failing" or "connection drops randomly" in a Node.js context are strong signals to use this skill. Do NOT use for browser/Web client issues. ## Skills relacionadas - [Chdb Datastore](https://skillsagentes.com/skills/clickhouse/agent-skills/chdb-datastore.md): Use when the user has tabular data (pandas DataFrame, parquet, csv, Arrow, json) and wants to filter, group, aggregate, join, or speed up slow pandas. Provides chDB DataStore — same pandas API, ClickHouse engine underneath. Also handles reading from S3, MySQL, PostgreSQL, MongoDB, ClickHouse Cloud, Iceberg, Delta Lake as DataFrames and joining across sources. TRIGGER when: user mentions DataFrame, parquet, csv, "fast pandas", "speed up pandas", or cross-source DataFrame joins; user imports `chdb.datastore` or `from datastore import DataStore`. SKIP this skill for raw SQL syntax (use chdb-sql instead), ClickHouse server administration, or non-Python DataStore API work. - [Clickhouse Architecture Advisor](https://skillsagentes.com/skills/clickhouse/agent-skills/clickhouse-architecture-advisor.md): MUST USE when designing ClickHouse architectures, selecting between ingestion or modeling patterns, or translating best practices into workload-specific system designs. Complements clickhouse-best-practices with decision frameworks and explicit provenance labels. - [Clickhouse Best Practices](https://skillsagentes.com/skills/clickhouse/agent-skills/clickhouse-best-practices.md): MUST USE when reviewing ClickHouse schemas, queries, or configurations. Contains 31 rules that MUST be checked before providing recommendations. Always read relevant rule files and cite specific rules in responses. - [Clickhouse Js Node Coding](https://skillsagentes.com/skills/clickhouse/agent-skills/clickhouse-js-node-coding.md): Write idiomatic application code with the ClickHouse Node.js client (`@clickhouse/client`). Use this skill whenever a user is *building* against the Node.js client — configuring the client, pinging, inserting rows in JSON or raw formats, selecting and parsing results, binding query parameters, managing sessions and temporary tables, working with data types or customizing JSON parsing. Do NOT use for browser/Web client code. - [Clickhouse Js Node Rowbinary](https://skillsagentes.com/skills/clickhouse/agent-skills/clickhouse-js-node-rowbinary.md): Generate TypeScript/JavaScript code that reads/decodes AND writes/encodes ClickHouse RowBinary streams for the ClickHouse HTTP server. Use this skill whenever a user wants to parse or produce `RowBinary`, `RowBinaryWithNames`, or `RowBinaryWithNamesAndTypes`. Node.js only, doesn't cover browsers. --- Skills Agentes · [Índice de páginas en markdown](https://skillsagentes.com/sitemap.md) · [Inicio](https://skillsagentes.com/index.md)