sql-formatter-org / sql-formatter-org/sql-formatter
In a window clause, "ROWS BETWEEN ..." should start a new line, it's not part of ORDER BY
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 456
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 3
Description
Input data
Which SQL and options did you provide as input?
SELECT
some_events.*,
sum(some_events.size) OVER (
ORDER BY time_stamp
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_size
FROM
some_events
Expected Output
SELECT
some_events.*,
sum(some_events.size) OVER (
ORDER BY
time_stamp
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_size
FROM
some_events
Actual Output
SELECT
some_events.*,
sum(some_events.size) OVER (
ORDER BY
time_stamp ROWS BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
) AS running_size
FROM
some_events
Usage
- How are you calling / using the library?
--sql-formatter -l duckdb -c '{"keywordCase": "upper", "dataTypeCase": "upper"}' filename - What SQL language(s) does this apply to?
-- Tried it on tsql and duckdb - Which SQL Formatter version are you using?
-- 15.6.6
A few examples of how DuckDB's team formats these clauses -
https://duckdb.org/2025/02/10/window-catchup.html
https://duckdb.org/2021/10/13/windowing.html
sql-formatter is great, thank you for the project!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported formatting with the DuckDB or T-SQL example using sql-formatter 15.6.6, then trace the formatter behavior for window clauses and ORDER BY. The work is done when ROWS BETWEEN starts on its own line as shown in the expected output without regressing other window-clause formatting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100