sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.32k stars 399 forks source link

Feature Request: ClickHouse dialect #614

Open derN3rd opened 1 year ago

derN3rd commented 1 year ago

Describe the Feature

Hey there, I'm currently very happy with sql-formatter in my code base, but I've just started to use ClickHouse for an analytics project and figured out that the formatting is breaking the SQL files (resulting in invalid queries).

Don't exactly know if one of the existing languages is similar to ClickHouse, but it seems not, as they have added a few custom keywords.

Their SQL reference is here: https://clickhouse.com/docs/en/sql-reference

Thanks in advance

Why do you want this feature? Dialect of ClickHouse seems to be different from already provided languages

nene commented 1 year ago

Thanks for the feature request.

From my first glance it indeed doesn't look very similar to any other SQL dialect I know of. Notably it has the $foo$heredoc$foo$ strings like Postgres, while supporting both "double quotes" and `backticks` for quoting identifiers like SQLite.

If you're interested in getting a support for it, you unfortunately need to put in some effort to make it happen. I'm open for a pull request, but I'm not really interested in implementing it by myself. Luckily for you, adding a support for a new dialect to sql-formatter is not that hard. You don't even need to fork sql-formatter to do so, you can just provide it a custom dialect definition.

Well, admittedly there's not that much of documentation there, but just copying an existing dialect implementation from sql-formatter source code and modifying it slightly should be pretty simple.

You can also look at the wiki, which documents syntax details of all the currently supported SQL dialects.