Style guide for the SQL formatter and beautifier

Sep 20, 2025, 10:11:10 AM

Table of contents

Indentation style

See the different indentation styles and formatting options for the SQL formatter. The indentation style controls the overall layout of the SQL query. Choose the one that fits your preferences. Below we list the formatting styles.

”Default” style

Here is an example of how the default formatting style 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” style

Here is an example of how the compact formatting style 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” style

Here is an example of how the collapsed formatting style 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” style

Here is an example of how the leading commas formatting style 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” style

Here is an example of how the collapsed formatting style 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” style

Here is an example of how the collapsed formatting style 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.