clickhouse-client: The ClickHouse Client
Get fluent in clickhouse-client — connect, create a database, load schema and data from files, aggregate over many rows, switch output formats, and run queries non-interactively for scripts and exports.
ClickHouse is a column-oriented store built for analytics — counting, grouping and summing over huge tables in milliseconds. Its client, clickhouse-client, is a plain SQL REPL: no dot-commands, just statements and a boxed result. We start from an empty prompt and build up real fluency one small thing at a time: creating a database, defining a MergeTree table, loading schema and events from files, aggregating with GROUP BY, reshaping output with FORMAT, and finally running the client non-interactively to feed scripts and exports. Writing a query and running it are taught as separate steps, so each idea lands on its own.
What you'll build
- Connect to ClickHouse and read its boxed result tables
- Create a database and a MergeTree table with a sort key
- Load schema and event data from .sql files
- Aggregate over many rows with GROUP BY
- Reshape output with FORMAT Vertical, CSV and JSONEachRow
- Run clickhouse-client non-interactively for scripts and exports
Contents
- Open a session
- Run your first query
- Leave the session
- List the databases
- Create a database
- Enter your database
- Confirm where you are
- Write a schema file
- Run a file
- See your tables
- Inspect a table
- Write a seed file
- Load the data
- Read a result
- Count the rows
- Aggregate with GROUP BY
- Group by user
- Lay out a wide row vertically
- Output as CSV
- Output as JSON rows
- Tune a setting, then see it
- Read the query plan
- Write a reusable query
- Run the saved query
- One query for a script
- Export to CSV
- Check the export
- Pipe a query in