ClickHouse SQL Formatter

Paste a ClickHouse query and get it formatted instantly. This formatter uses a real ClickHouse grammar rather than approximating it with MySQL, so ClickHouse-only syntax survives intact — and it reads {name:Type} query parameters, so you can fill them in and get a runnable query back.

ClickHouse syntax it handles

A generic formatter mangles dialect-specific syntax or refuses it outright. These are the ClickHouse constructs this formatter is tested against.

{name:Type}

ClickHouse query parameters are detected as real parameters, named after the parameter rather than its type. Fill start_ts once and every use updates; DateTime64, Array and Nullable types map to the right input.

PREWHERE

Discovered as its own editable filter clause alongside WHERE, so you can tune the clause that actually drives ClickHouse's read path.

ARRAY JOIN

Kept as a single clause instead of being split into a phantom JOIN.

attributes['key']

Map and array subscripts are preserved exactly, including dotted keys such as attributes_string['http.method'].

quantile(0.95)(x)

Parametric aggregate functions keep both argument lists tight together.

column$$name

Materialised columns containing $$ are treated as identifiers, not as an unterminated dollar-quoted string.

GLOBAL IN

Distributed-query operators are left verbatim, and the subquery inside them stays editable.

SETTINGS / FORMAT

Trailing clauses are recognised as clause boundaries, so editing a WHERE never swallows them.

ClickHouse formatter FAQ

Does it understand ClickHouse query parameters?

Yes. ClickHouse's {name:Type} parameters are detected, grouped by name, and typed from their declared type. Two parameters that share a type — say {start_ts:UInt64} and {end_ts:UInt64} — stay separate, and filling one does not overwrite the other. Switch the output to filled SQL and you get a query you can run directly.

Can it format a query built from several CTEs?

Yes, and it can edit them. Every WHERE and PREWHERE clause in the query is listed by the CTE it belongs to, so you can pick one and edit it as an AND/OR tree or node graph. Edits are spliced back into that exact clause and nothing else in the query moves.

Is my ClickHouse query sent to a server?

No. Formatting runs entirely in your browser, so production queries, table names and embedded values never leave your machine.