ClickHouse Format Online
Format ClickHouse analytical SQL without hiding the clauses that affect scan volume, row expansion, or aggregation. The formatter keeps PREWHERE, ARRAY JOIN, array expressions, and aggregate functions visible in a reviewable layout.
ClickHouse clauses that deserve clear boundaries
PREWHERE is an execution-oriented filter and should remain visibly distinct from WHERE. ARRAY JOIN can expand the result set, while aggregate combinators such as -State, -Merge, and -If change how a metric is built. A formatter that only inserts spaces can make these differences difficult to review.
Use the ClickHouse page for dashboards, materialized-view definitions, event analytics, and maintenance scripts. The AST-based formatter keeps nested expressions grouped while separating the stages that change filtering, cardinality, and aggregation.
- Place date and partition filters where scan reduction is easy to audit.
- Keep ARRAY JOIN sources connected to the arrays they expand.
- Preserve aggregate combinator names and their aliases exactly.
SELECT
toStartOfHour(timestamp) AS hour_bucket,
quantileState(0.95)(latency_ms) AS p95_state
FROM analytics.http_events
PREWHERE event_date >= today() - 7
GROUP BY hour_bucket;Continue with the formatter
Ready to format your SQL?
Choose a dialect, format a query, and review the result with a Git-style diff.
Open SQL Formatter