SQL formatting style guide

See the different indentation styles and formatting options that our SQL formatter offers.

Remember to set the database engine in the “Settings” => “Database engine” as this also influences the formatting.

Indentation style

The indentation style controls the overall layout and readability of your SQL. Choose the one that fits your preferences.

”Default” indentation

Here is an example of how the default indentation looks:

SELECT
  c.customer_id,
  c.create_date
FROM
  customer c
  LEFT JOIN payment p ON c.customer_id = p.customer_id
WHERE
  c.create_date > CURRENT_DATE - INTERVAL '1 month'
  AND p.payment_id IS NULL
GROUP BY
  c.customer_id,
  c.create_date;

Description:

  • Uses uppercase for keywords, data types, and function names
  • Defaults to 2-space indentation
  • Places major clauses on separate lines for readability

Why use it: A balanced option ideal for most use cases—clear structure without excessive line length.

”Compact” indentation

Here is an example of how the compact indentation looks:

SELECT c.customer_id, c.create_date
FROM customer c
LEFT JOIN payment p ON c.customer_id = p.customer_id
WHERE c.create_date > CURRENT_DATE - INTERVAL '1 month' AND p.payment_id IS NULL
GROUP BY c.customer_id, c.create_date;

Description:

  • Uses uppercase for keywords, data types, and function names
  • Defaults to 2-space indentation
  • Keeps more content on each line

Why use it: Good when you prefer shorter query height while retaining some structure.

”Collapsed” indentation

Here is an example of how the collapsed indentation looks:

SELECT c.customer_id, c.create_date FROM customer c LEFT JOIN payment p ON c.customer_id = p.customer_id WHERE c.create_date > CURRENT_DATE - INTERVAL '1 month' AND p.payment_id IS NULL GROUP BY c.customer_id, c.create_date;

Description:

  • Uses uppercase for keywords, data types, and function names
  • Formats the SQL as a single line

Why use it: Handy for embedding SQL in code or logs where multiline output is undesirable. Less ideal for code reviews.

”Leading commas” indentation

Here is an example of how the leading commas indentation looks:

SELECT
  c.customer_id
 ,c.email
 ,c.name
 ,c.create_date
FROM
  customer c
  LEFT JOIN payment p ON c.customer_id = p.customer_id
WHERE
  c.create_date > CURRENT_DATE - INTERVAL '1 month'
  AND p.payment_id IS NULL
GROUP BY
  c.customer_id;

Description:

  • Similar to default, but uses leading commas

Why use it: Leading commas make it easy to add or remove columns with cleaner diffs and fewer comma-related edits.

”Right aligned” indentation

Here is an example of how the collapsed indentation looks:

   SELECT c.customer_id,
          c.create_date
     FROM customer c
     LEFT JOIN payment p ON c.customer_id = p.customer_id
    WHERE c.create_date > CURRENT_DATE - INTERVAL '1 month'
      AND p.payment_id IS NULL
 GROUP BY c.customer_id;

Why use it: Emphasizes clause alignment for quick visual scanning, especially in longer statements.

”Left aligned” indentation

Here is an example of how the collapsed indentation looks:

SELECT    c.customer_id,
          c.create_date
FROM      customer c
LEFT JOIN payment p ON c.customer_id = p.customer_id
WHERE     c.create_date > CURRENT_DATE - INTERVAL '1 month'
AND       p.payment_id IS NULL
GROUP BY  c.customer_id;

Why use it: Highlights clause keywords by lining them up on the left, which some teams prefer for consistency.

Tab width

Specifies the number of spaces used for indentation. The default tab width is 2 spaces. Only the default and leading commas styles respect this setting.