Max line width
maxLineWidth is the line width dfmt lays out to. A construct that fits on its line stays there.
One that does not is broken across lines, and each of the pieces is measured against the same
width.
Default: 80. A typical select list or where clause fits on its keyword's line at 80, and a
file still reads in a split editor or a review diff. Raise it to 100 or 120 for a team that reads
SQL on wide screens: a wider line keeps more clause bodies beside their keyword, and fewer
statements come apart at all.
A statement that fits takes one line. Narrow the width and it comes apart, one clause per line.
Narrow it further and a clause whose body no longer fits its line stacks the items beneath the
keyword. Each clause decides for itself, so from customers stays on its line beside a select
list that has stacked.
The same statement at 80, 40 and 30
select customer_id, name, email from customers where status = 'active'select customer_id, name, email from customers where status = 'active'select customer_id, name, email from customers where status = 'active'select customer_id, name, email
from customers
where status = 'active'select customer_id, name, email from customers where status = 'active'select
customer_id,
name,
email
from customers
where status = 'active'Width is not the only reason a construct breaks. A list can stack because listLayout
says so, or because the author stacked it and preserveBreaks is on. And an
and/or chain inside a case when condition is never broken for width, because the CASE decides
the shape of its own branches.
0 turns width off, and does not keep your breaks
maxLineWidth: 0 means no line is ever too wide, so nothing breaks because it did not fit. It is
not "keep the line breaks I wrote". Everything that breaks for another reason still breaks, each
clause still takes its own line, and a list you stacked by hand is joined back up. Below, the author
stacked the select list and put and y < 2 on its own line. Neither break was asked for by anything
but the typing, so neither survives. preserveBreaks is the option that keeps
them; set the two together if that is what you want.
One more consequence: with no width, no query is "short", so the one-line collapse of short
queries (collapseShortStatements) goes off with it — for a statement and for
every subquery in it. That is why 0 is not the same as a very large width, which collapses short
queries as usual.
select
a,
b, c,
d
from t
where x > 1
and y < 2select a, b, c, d
from t
where x > 1 and y < 2