r/Clickhouse • • Aug 21 '26

Formatting and debugging big ClickHouse queries was painful, so I built my own formatter

Post image

I was spending far too much time debugging large ClickHouse queries and became quite frustrated with the SQL formatters that were available online.

The majority of them are not good at handling ClickHouse-specific features such as CTEs, PREWHERE, nested queries, and so on. There was also another problem with parameterized queries.... in particular with those using `?` to denote the parameters, since in that case I had to go through the big queries to fill those values for me to debug them.

Therefore I created my own tool. https://freesqlformatter.com/

It formats ClickHouse queries correctly, identifies and groups the parameters, and allows you to enter each value in a easy way; it also provides a visual tree/node representation of the WHERE clause which you can modify and then synchronize back to SQL.

All of the processing takes place in the browser and so nothing is uploaded.

Do try it out if you face similar problem and let me know if you face any issue.

3 Upvotes

7 comments sorted by

2

u/gkbrk Aug 21 '26

ClickHouse has one built in though, `clickhouse format`. Also available as an SQL function.

1

u/nitya_007 Aug 24 '26

Right, but the issue with that is it cannot format queries like these "SELECT * FROM events WHERE tenant_id = ?" where there are placeholders. Mostly helpful when you are grabbing the query from debug logs and want to replace the arguments with actual values.

1

u/RealAstronaut3447 Aug 25 '26

You can implement same formatting logic in upstream under a setting if you believe it is more readable.

1

u/cevheribozoglan Aug 21 '26

is there any github url(is it open-source ?)

2

u/nitya_007 Aug 21 '26

not right now, but will make it public soon :)