mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
2.4 KiB
2.4 KiB
clickhouse-format
Allows formatting input queries.
Keys:
--help
or-h
— Produce help message.--query
— Format 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.--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.
Examples
- Formatting a query:
$ clickhouse-format --query "select number from numbers(10) where number%2 order by number desc;"
Result:
SELECT number
FROM numbers(10)
WHERE number % 2
ORDER BY number DESC
- Highlighting and single line:
$ clickhouse-format --oneline --hilite <<< "SELECT sum(number) FROM numbers(5);"
Result:
SELECT sum(number) FROM numbers(5)
- Multiqueries:
$ clickhouse-format -n <<< "SELECT * FROM (SELECT 1 AS x UNION ALL SELECT 1 UNION DISTINCT SELECT 3);"
Result:
SELECT *
FROM
(
SELECT 1 AS x
UNION ALL
SELECT 1
UNION DISTINCT
SELECT 3
)
;
- Obfuscating:
$ clickhouse-format --seed Hello --obfuscate <<< "SELECT cost_first_screen BETWEEN a AND b, CASE WHEN x >= 123 THEN y ELSE NULL END;"
Result:
SELECT treasury_mammoth_hazelnut BETWEEN nutmeg AND span, CASE WHEN chive >= 116 THEN switching ELSE ANYTHING END;
Same query and another seed string:
$ clickhouse-format --seed World --obfuscate <<< "SELECT cost_first_screen BETWEEN a AND b, CASE WHEN x >= 123 THEN y ELSE NULL END;"
Result:
SELECT horse_tape_summer BETWEEN folklore AND moccasins, CASE WHEN intestine >= 116 THEN nonconformist ELSE FORESTRY END;
- Adding backslash:
$ clickhouse-format --backslash <<< "SELECT * FROM (SELECT 1 AS x UNION ALL SELECT 1 UNION DISTINCT SELECT 3);"
Result:
SELECT * \
FROM \
( \
SELECT 1 AS x \
UNION ALL \
SELECT 1 \
UNION DISTINCT \
SELECT 3 \
)