← All bricks

clickhouse · Beginner

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

  1. Open a session
  2. Run your first query
  3. Leave the session
  4. List the databases
  5. Create a database
  6. Enter your database
  7. Confirm where you are
  8. Write a schema file
  9. Run a file
  10. See your tables
  11. Inspect a table
  12. Write a seed file
  13. Load the data
  14. Read a result
  15. Count the rows
  16. Aggregate with GROUP BY
  17. Group by user
  18. Lay out a wide row vertically
  19. Output as CSV
  20. Output as JSON rows
  21. Tune a setting, then see it
  22. Read the query plan
  23. Write a reusable query
  24. Run the saved query
  25. One query for a script
  26. Export to CSV
  27. Check the export
  28. Pipe a query in