Skip to main content
The 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:
Reformat a SQL query given on the command line:
Reformat a SQL query already stored in a file:

Flags

The sqlfmt command supports the following flags.

Examples

Reformat a query with constrained column width

Using the interactive query formatter, output with the default column width (80 columns):
  1. Start the interactive query formatter:
  2. Press Enter.
  3. Run the query:
  4. Press CTRL+D.
Using the command line, output with the column width set to 40:

Reformat a query with vertical alignment

Output with the default vertical alignment:
Output with vertical alignment:

Reformat a query with simplification of parentheses

Output with the default simplification of parentheses:
Output with no simplification of parentheses:

See also