mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Formatting a query
This commit is contained in:
parent
bebee01b34
commit
8931958e78
@ -10,6 +10,7 @@ Allows formatting input queries.
|
||||
Keys:
|
||||
|
||||
- `--help` or`-h` — Produce help message.
|
||||
- `--query` — Formatting queries of any length and complexity.
|
||||
- `--hilite` — Add syntax highlight with ANSI terminal escape sequences.
|
||||
- `--oneline` — Format in single line.
|
||||
- `--quiet` or `-q` — Just check syntax, no output on success.
|
||||
@ -20,7 +21,22 @@ Keys:
|
||||
|
||||
## Examples {#examples}
|
||||
|
||||
1. Highlighting and single line:
|
||||
1. Formatting a query:
|
||||
|
||||
```bash
|
||||
$ clickhouse-format --query "select number from numbers(10) where number%2 order by number desc;"
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
```sql
|
||||
SELECT number
|
||||
FROM numbers(10)
|
||||
WHERE number % 2
|
||||
ORDER BY number DESC
|
||||
```
|
||||
|
||||
2. Highlighting and single line:
|
||||
|
||||
```bash
|
||||
$ clickhouse-format --oneline --hilite <<< "SELECT sum(number) FROM numbers(5);"
|
||||
@ -32,7 +48,7 @@ Result:
|
||||
SELECT sum(number) FROM numbers(5)
|
||||
```
|
||||
|
||||
2. Multiqueries:
|
||||
3. Multiqueries:
|
||||
|
||||
```bash
|
||||
$ clickhouse-format -n <<< "SELECT * FROM (SELECT 1 AS x UNION ALL SELECT 1 UNION DISTINCT SELECT 3);"
|
||||
@ -53,7 +69,7 @@ FROM
|
||||
;
|
||||
```
|
||||
|
||||
3. Obfuscating:
|
||||
4. Obfuscating:
|
||||
|
||||
```bash
|
||||
$ clickhouse-format --seed Hello --obfuscate <<< "SELECT cost_first_screen BETWEEN a AND b, CASE WHEN x >= 123 THEN y ELSE NULL END;"
|
||||
@ -77,7 +93,7 @@ Result:
|
||||
SELECT horse_tape_summer BETWEEN folklore AND moccasins, CASE WHEN intestine >= 116 THEN nonconformist ELSE FORESTRY END;
|
||||
```
|
||||
|
||||
4. Adding backslash:
|
||||
5. Adding backslash:
|
||||
|
||||
```bash
|
||||
$ clickhouse-format --backslash <<< "SELECT * FROM (SELECT 1 AS x UNION ALL SELECT 1 UNION DISTINCT SELECT 3);"
|
||||
|
Loading…
Reference in New Issue
Block a user