cockroach sqlfmt changes the textual formatting of one or more SQL queries. It recognizes all SQL extensions supported by CockroachDB.
A web interface to this feature is also available.
This feature is in and subject to change. To share feedback and/or issues, contact Support.
Synopsis
Use the query formatter interactively:Flags
Thesqlfmt command supports the following flags.
| Flag | Description | Default value |
|---|---|---|
--execute -e | Reformat the given SQL query, without reading from standard input. | N/A |
--print-width | Desired column width of the output. | 80 |
--tab-width | Number of spaces occupied by a tab character on the final display device. | 4 |
--use-spaces | Always use space characters for formatting; avoid tab characters. | Use tabs. |
--align | Use vertical alignment during formatting. | Do not align vertically. |
--no-simplify | Avoid removing optional grouping parentheses during formatting. | Remove unnecessary grouping parentheses. |
Examples
Reformat a query with constrained column width
Using the interactive query formatter, output with the default column width (80 columns):-
Start the interactive query formatter:
- Press Enter.
-
Run the query:
-
Press CTRL+D.
40:

