Skip to main content

Max Line Width

maxLineWidth is the width the formatter lays out to. A construct that fits stays on one line; one that does not is broken across lines.

Default: 80.

maxLineWidth: 0 turns width-based breaking off entirely. Nothing is measured, so layout comes from the line breaks already in the source rather than from a target width.

Width is not the only thing that decides a break — listLayout, consistentSiblings and preserveBreaks all participate, and a construct can break for reasons other than not fitting. The examples below are the width story on its own.

AND/OR inside a CASE WHEN condition is not broken by width. The CASE decides the shape of its own branches, so a compound WHEN condition is not fragmented to satisfy the target width.

SELECT fits within max width

Short SELECT list fits within maxLineWidth — stays compact.

select a, b from t
select a, b from t

SELECT exceeds max width

Long SELECT list exceeds maxLineWidth — breaks to vertical.

select very_long_column_a, very_long_column_b, very_long_column_c from t
select
very_long_column_a,
very_long_column_b,
very_long_column_c
from t

Max width disabled preserves user layout

maxLineWidth=0 (disabled) — falls back to trivia detection (user wrote compact).

select very_long_column_a, very_long_column_b, very_long_column_c from t
select
very_long_column_a, very_long_column_b, very_long_column_c
from t

GROUP BY exceeds max width

select a from t group by very_long_col_a, very_long_col_b, very_long_col_c
select a
from t
group by
very_long_col_a,
very_long_col_b,
very_long_col_c

Function args exceed max width

select coalesce(very_long_expr_a, very_long_expr_b, very_long_expr_c) from t
select
coalesce(
very_long_expr_a,
very_long_expr_b,
very_long_expr_c
)
from t

Function args fit within max width

Short function args fit within maxLineWidth — stays compact.

select coalesce(a, b) from t
select coalesce(a, b) from t

ALWAYS overrides max width

ALWAYS mode ignores maxLineWidth — always breaks even if fits.

select a, b from t
select a, b from t

NEVER overrides max width

NEVER mode ignores maxLineWidth — never breaks even if exceeds.

select very_long_column_a, very_long_column_b, very_long_column_c from t
select
very_long_column_a,
very_long_column_b,
very_long_column_c
from t

AND/OR fits within max width

Short WHERE condition fits within maxLineWidth — stays compact.

select a from t where x > 1 and y > 2
select a from t where x > 1 and y > 2

AND/OR exceeds max width

Long WHERE condition exceeds maxLineWidth — breaks AND/OR to vertical.

select a from t where very_long_column_name > 100 and another_long_column > 200 and third_column > 300
select a
from t
where
very_long_column_name > 100
and another_long_column > 200
and third_column > 300

AND/OR in JOIN ON exceeds max width

select a from t1 inner join t2 on t1.very_long_id = t2.very_long_id and t1.another_col = t2.another_col
select a
from t1
inner join t2
on
t1.very_long_id = t2.very_long_id
and t1.another_col = t2.another_col

AND/OR in HAVING exceeds max width

select a, count(*) from t group by a having count(*) > 10 and sum(very_long_column_name) > 1000
select a, count(*)
from t
group by a
having
count(*) > 10
and sum(
very_long_column_name
) > 1000

AND/OR inside CASE WHEN suppressed

AND/OR inside CASE WHEN conditions should not break even when maxLineWidth is set.

select case when a > 1 and b > 2 then 'yes' else 'no' end from t
select
case
when a > 1 and b > 2 then 'yes'
else 'no'
end
from t

Long arithmetic chain with max width

select total_amount * discount_rate + tax_amount - refund_amount + adjustment_value from orders
select
total_amount * discount_rate + tax_amount - refund_amount + adjustment_value
from orders

CASE WHEN exceeds max width

When a WHEN clause body exceeds maxLineWidth, the THEN keyword breaks to a new indented line.

select case when very_long_column > 100 then 'yes' else 'no' end from t
select
case
when very_long_column > 100
then 'yes'
else 'no'
end
from t