> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Guide to using the format utility for working with ClickHouse data formats

# clickhouse-format

Allows formatting input queries.

Keys:

* `--help` or`-h` — Produce help message.
* `--query` — Format queries of any length and complexity.
* `--hilite` or `--highlight` — Add syntax highlight with ANSI terminal escape sequences.
* `--oneline` — Format in single line.
* `--max_line_length` — Format in single line queries with length less than specified.
* `--comments` — Keep comments in the output.
* `--quiet` or `-q` — Just check syntax, no output on success.
* `--multiquery` or `-n` — Allow multiple queries in the same file.
* `--obfuscate` — Obfuscate instead of formatting.
* `--seed <string>` — Seed arbitrary string that determines the result of obfuscation.
* `--backslash` — Add a backslash at the end of each line of the formatted query. Can be useful when you copy a query from web or somewhere else with multiple lines, and want to execute it in command line.
* `--semicolons_inline` — In multiquery mode, write semicolons on last line of query instead of a new line.

<h2 id="examples">
  Examples
</h2>

1. Formatting a query:

```bash title="Query" theme={null}
$ clickhouse-format --query "select number from numbers(10) where number%2 order by number desc;"
```

```bash title="Response" theme={null}
SELECT number
FROM numbers(10)
WHERE number % 2
ORDER BY number DESC
```

2. Highlighting and single line:

```bash title="Query" theme={null}
$ clickhouse-format --oneline --hilite <<< "SELECT sum(number) FROM numbers(5);"
```

```sql title="Response" theme={null}
SELECT sum(number) FROM numbers(5)
```

3. Multiqueries:

```bash title="Query" theme={null}
$ clickhouse-format -n <<< "SELECT min(number) FROM numbers(5); SELECT max(number) FROM numbers(5);"
```

```sql title="Response" theme={null}
SELECT min(number)
FROM numbers(5)
;

SELECT max(number)
FROM numbers(5)
;

```

4. Obfuscating:

```bash title="Query" theme={null}
$ clickhouse-format --seed Hello --obfuscate <<< "SELECT cost_first_screen BETWEEN a AND b, CASE WHEN x >= 123 THEN y ELSE NULL END;"
```

```sql title="Response" theme={null}
SELECT treasury_mammoth_hazelnut BETWEEN nutmeg AND span, CASE WHEN chive >= 116 THEN switching ELSE ANYTHING END;
```

Same query and another seed string:

```bash title="Query" theme={null}
$ clickhouse-format --seed World --obfuscate <<< "SELECT cost_first_screen BETWEEN a AND b, CASE WHEN x >= 123 THEN y ELSE NULL END;"
```

```sql title="Response" theme={null}
SELECT horse_tape_summer BETWEEN folklore AND moccasins, CASE WHEN intestine >= 116 THEN nonconformist ELSE FORESTRY END;
```

5. Adding backslash:

```bash title="Query" theme={null}
$ clickhouse-format --backslash <<< "SELECT * FROM (SELECT 1 AS x UNION ALL SELECT 1 UNION DISTINCT SELECT 3);"
```

```sql title="Response" theme={null}
SELECT * \
FROM  \
( \
    SELECT 1 AS x \
    UNION ALL \
    SELECT 1 \
    UNION DISTINCT \
    SELECT 3 \
)
```
