Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Development Version
-------------------

Nothing yet.
Bug Fixes

* `format(sql, reindent_aligned=True)` no longer runs consecutive statements
together on one line. `reindent_aligned` implies `strip_whitespace`, which
removes the whitespace separating the statements, and unlike `reindent` the
aligned filter never put a separator back (issue673).


Release 0.6.0 (Aug 13, 2026)
Expand Down
11 changes: 11 additions & 0 deletions sqlparse/filters/aligned_indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, char=' ', n='\n'):
self.indent = 0
self.char = char
self._max_kwd_len = len('select')
self._last_stmt = None

def nl(self, offset=1):
# offset = 1 represent a single space after SELECT
Expand Down Expand Up @@ -133,4 +134,14 @@ def _process(self, tlist):

def process(self, stmt):
self._process(stmt)

# reindent_aligned implies strip_whitespace, so the whitespace that
# separated this statement from the previous one is gone by now. Put a
# separator back, the way ReindentFilter does, or the statements are
# emitted glued together.
if self._last_stmt is not None:
nl = '\n' if str(self._last_stmt).endswith('\n') else '\n\n'
stmt.tokens.insert(0, sql.Token(T.Whitespace, nl))

self._last_stmt = stmt
return stmt
10 changes: 10 additions & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ def test_window_functions(self):
'(PARTITION BY b, c ORDER BY d DESC) as row_num',
' from table'])

def test_multiple_statements_are_separated(self):
# issue673
sql = 'select a from t1;\nselect b from t2;\n'
assert self.formatter(sql) == '\n'.join([
'select a',
' from t1;',
'',
'select b',
' from t2;'])


class TestSpacesAroundOperators:
@staticmethod
Expand Down