Skip to content

In a window clause, "ROWS BETWEEN ..." should start a new line, it's not part of ORDER BY #892

@tgs

Description

@tgs

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions