| name | clickhouse-core-workflow-b |
| description | Insert, query, and aggregate data in ClickHouse with real SQL patterns.
Use when writing analytical queries, inserting data at scale, building
dashboards, or implementing materialized views for pre-aggregation.
Trigger with "clickhouse query", "clickhouse insert", "clickhouse aggregate",
"clickhouse materialized view", "clickhouse SQL".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*) |
| version | 1.7.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","database","analytics","clickhouse","olap"] |
| compatibility | Designed for Claude Code |
ClickHouse Insert & Query (Core Workflow B)
Overview
Move data into ClickHouse efficiently, then answer analytical questions with
aggregations, funnels, retention, window functions, and materialized views.
This skill covers the read/write half of the core workflow: the fast-path insert
patterns that avoid "too many parts", the parameterized query API for Node.js,
and pre-aggregation via materialized views. The high-frequency patterns live
inline below; the deep query library and advanced engine patterns are broken out
into references/ so you can drill in only when you need them.
Prerequisites
- Tables already created — run
clickhouse-core-workflow-a first if not.
@clickhouse/client installed and connected (CLICKHOUSE_HOST, CLICKHOUSE_USER,
CLICKHOUSE_PASSWORD in the environment).
- A target database/table (examples use
analytics.events).
Instructions
Step 1: Bulk insert (the fast path)
Batch rows and let the client buffer. ClickHouse writes a new "part" per INSERT,
so many tiny inserts are the number-one performance mistake.
import { createClient } from '@clickhouse/client';
const client = createClient({
url: process.env.CLICKHOUSE_HOST!,
username: process.env.CLICKHOUSE_USER ?? 'default',
password: process.env.CLICKHOUSE_PASSWORD ?? '',
});
await client.insert({
table: 'analytics.events',
values: events,
format: 'JSONEachRow',
});