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 src/formatter/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,12 @@ impl<'a> Formatter<'a> {
}

if !self.config.compact_ctes {
lines.push(")".to_string());
let is_last = i == ctes.len() - 1;
lines.push(if is_last {
")".to_string()
} else {
"),".to_string()
});
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/dbt/select_cte_multi.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
with

a as (

select 1 as x

),
b as (

select 2 as y

)

select *

from
a,
b;
1 change: 1 addition & 0 deletions tests/fixtures/dbt/select_cte_multi.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WITH a AS (SELECT 1 AS x), b AS (SELECT 2 AS y) SELECT * FROM a, b
5 changes: 5 additions & 0 deletions tests/fixtures_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ fn dbt_select_cte() {
run_fixture(Style::Dbt, "select_cte");
}

#[test]
fn dbt_select_cte_multi() {
run_fixture(Style::Dbt, "select_cte_multi");
}

// ── GitLab fixtures ─────────────────────────────────────────────────────

#[test]
Expand Down