SQL format / minify
sql_formatFormat SQL text or .sql files into readable clauses with indentation and case options, or minify statements to one line while keeping or dropping comments.
Instructions
Format SQL (one clause per line, indented sub-queries, CASE blocks, JOIN … ON with AND/OR, CREATE TABLE column lists) or minify it to one line per statement. Options: keyword case (UPPER, lower, keep), indent (2, 4, tab), trailing or leading commas, keep/drop comments when minifying. Dialect-neutral tokenizer: understands -- and /* */ comments, '' and E''' strings, "x", x and [x] identifiers, $$ dollar quotes, ::casts, JSON operators, :name/$1/? parameters. Only re-spaces; never runs anything. Give "text" or a file "path". Web version: https://s3eidat.github.io/sql-format/
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | "format" (default) or "minify". | format |
| path | No | Or: a path to a .sql file (UTF-8; use this for big inputs). | |
| text | No | The SQL as inline text. | |
| commas | No | Put list commas at line ends (trailing) or starts (leading). | trailing |
| indent | No | Indentation: 2, 4 or "tab". | 2 |
| output | No | Optional: also write the result to this file path (or folder ending in "/"). The result text is then left out of the reply. Results over 1,000,000 characters are always written to a file. | |
| keywordCase | No | Keyword and built-in function case. | upper |
| keepComments | No | Minify only: keep comments (as /* */). Optimizer hints /*+ */ and /*! */ are always kept. |