# SQL Formatter Pretty-print SQL: uppercase keywords, clause line breaks, paren indentation. Pure stdlib. ``` python scripts/run.py query.sql echo "select a,b from t where x=1 order by a" | python scripts/run.py - python scripts/run.py query.sql --indent " " python scripts/run.py query.sql --no-upper ``` A formatter, not a validator — it won't reject malformed SQL. --- name: sql-formatter display_name: SQL Formatter description: "Pretty-print and indent a SQL query: uppercase keywords, put major clauses (SELECT/FROM/WHERE/JOIN/GROUP BY/ORDER BY) on their own lines, indent subqueries. Triggers: format sql, pretty print sql, beautify query, indent sql." --- # SQL Formatter Reformat a messy one-line SQL query into readable, indented form. ## When to use The user pastes a hard-to-read SQL statement and wants it beautified — keywords uppercased and each major clause on its own line. ## How to use Run `scripts/run.py` on a file or stdin: - `python scripts/run.py query.sql` — format a file. - `echo "select a,b from t where x=1 order by a" | python scripts/run.py -` — format from stdin. - `python scripts/run.py query.sql --indent " "` — use 4-space indents for nested parens. - `python scripts/run.py query.sql --no-upper` — keep original keyword casing. Major clauses (SELECT, FROM, WHERE, JOIN variants, GROUP BY, ORDER BY, HAVING, LIMIT, UNION, …) each begin a new line; parentheses increase indent depth. ## Pitfalls - This is a structural pretty-printer, not a SQL parser/validator — it won't catch syntax errors. - Dialect-specific or exotic syntax may format imperfectly; the goal is readability. - String literals and `--`/`/* */` comments are preserved as single tokens.
SQL Formatter by langbot-team
Pretty-print and indent a SQL query: uppercase keywords, put major clauses (SELECT/FROM/WHERE/JOIN/GROUP BY/ORDER BY) on their own lines, indent subqueries.
Loading...