Skip to content

Commit b2d2add

Browse files
Copilotgit-hulk
andauthored
Document -beautify flag with example (#249)
--------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: git-hulk <4987594+git-hulk@users.noreply.github.com>
1 parent 3b8db28 commit b2d2add

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,46 @@ On macOS:
4444
$ brew install clickhouse-sql-parser
4545
```
4646

47-
Parse ClickHouse SQL into AST or beautify ClickHouse SQL format:
47+
Parse ClickHouse SQL into AST or format ClickHouse SQL:
4848

4949
```bash
5050
## Parse query into AST
5151
$ clickhouse-sql-parser "SELECT * FROM clickhouse WHERE a=100"
5252

53-
## Beautify query
53+
## Format query (compact, single-line output)
5454
$ clickhouse-sql-parser -format "SELECT * FROM clickhouse WHERE a=100"
5555

56+
## Beautify query (formatted with proper indentation and line breaks)
57+
$ clickhouse-sql-parser -beautify "SELECT * FROM clickhouse WHERE a=100"
58+
5659
## Parse query from file
57-
$ clickhouse-sql-parser -file ./test.sql
60+
$ clickhouse-sql-parser -f ./test.sql
61+
```
62+
63+
### Beautify SQL Example
64+
65+
The `-beautify` flag formats SQL with proper indentation and line breaks, making complex queries more readable:
66+
67+
```bash
68+
# Input (compact, hard to read)
69+
$ clickhouse-sql-parser -beautify "SELECT user_id, COUNT(*) AS total, AVG(amount) AS avg_amount FROM orders WHERE status='completed' AND created_at>'2024-01-01' GROUP BY user_id HAVING COUNT(*)>5 ORDER BY total DESC LIMIT 10"
70+
71+
# Output (beautified, easy to read)
72+
SELECT
73+
user_id,
74+
COUNT(*) AS total,
75+
AVG(amount) AS avg_amount
76+
FROM orders
77+
WHERE
78+
status = 'completed'
79+
AND
80+
created_at > '2024-01-01'
81+
GROUP BY
82+
user_id
83+
HAVING COUNT(*) > 5
84+
ORDER BY
85+
total DESC
86+
LIMIT 10
5887
```
5988

6089
- Parsed tree(AST) back into a SQL statement

0 commit comments

Comments
 (0)