Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [Unreleased]

- Fix bug with aggregate filter where clause

## [0.6.0] - 2025-08-21

- Add preprocessors config that allows applying text transforms to the input before parsing
Expand Down
2 changes: 2 additions & 0 deletions lib/activerecord-pg-format-db-structure/indenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def indent
output.append_token
output.pop_scope
output.append_scope(type:, indent: 0)
in { current_token: WHERE, inside: PARENS }
output.append_token
in {
current_token: FROM | WHERE | GROUP | ORDER | WINDOW | HAVING | LIMIT | OFFSET | FETCH | FOR | UNION |
INTERSECT | EXCEPT => token_type
Expand Down
16 changes: 16 additions & 0 deletions spec/activerecord-pg-format-db-structure/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,21 @@
);
SQL
end

it "handles filter where clauses" do
formatter = described_class.new

source = +<<~SQL
select range_agg(my_range) filter (where true),
range_agg(my_range) filter (where false)
from my_table
SQL

expect(formatter.format(source)).to eq(<<~SQL)
SELECT range_agg(my_range) FILTER (WHERE true),
range_agg(my_range) FILTER (WHERE false)
FROM my_table;
SQL
end
end
end