about

sqlfmt is an online SQL formatter. It is pronounced sequel fumpt. Its purpose is to beautifully format SQL statements.

Features

Usage

There is a box in which to paste or type SQL statements. Multiple statements are supported by separating them with a semicolon (;). The slider below the box controls the desired maximum line width in characters. Various options on the side control tab/indentation width, the use of spaces or tabs, simplification, and alignment modes. Simplification causes the formatter to remove unneeded parentheses and words when the meaning will be the same without them.

There are four alignment modes. The default, no, uses left alignment. partial right aligns keywords at the width of the longest keyword at the beginning of all lines immediately below. full is the same as partial but the keywords AND and OR are deindented, in a style similar to the sqlite tests. other is like partial but instead of deindenting AND and OR, their arguments are instead indented.

no:

SELECT
    a
FROM
    t
WHERE
    c
    AND b
    OR d

partial:

SELECT a
  FROM t
 WHERE c
       AND b
       OR d

full:

SELECT a
  FROM t
 WHERE c
   AND b
    OR d

other:

SELECT a
  FROM t
 WHERE    c
          AND
            b
       OR d

Background

sqlfmt was inspired by prettier. It is based on a paper describing a layout algorithm. A blog post describes a bit more.
index editor config
by @mjibson
code: github.com/mjibson/sqlfmt