Skip to content

Cannot parse named windows with modifiers #999

Closed

Description

@jesse-shopify

sqlparser-rs only supports named windows that are an identifier. This is fine for queries like:

SELECT sum(salary) OVER w, avg(salary) OVER w
  FROM empsalary
  WINDOW w AS (PARTITION BY depname ORDER BY salary DESC);

However, it is insufficient for queries in at least BigQuery and MySQL where modifiers can be added to the named window in the OVER clause.

MySQL named window example

SELECT
  DISTINCT year, country,
  FIRST_VALUE(year) OVER (w ORDER BY year ASC) AS first,
  FIRST_VALUE(year) OVER (w ORDER BY year DESC) AS last
FROM sales
WINDOW w AS (PARTITION BY country)

BigQuery named window example

SELECT item, purchases, category, LAST_VALUE(item)
  OVER (
    item_window
    ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
  ) AS most_popular
FROM Produce
WINDOW item_window AS (
  PARTITION BY category
  ORDER BY purchases)

This would build upon prior to work:

Activity

  1. alamb commented on Oct 20, 2023

    @alamb
    Contributor

    Thanks for the report @jesse-shopify -- any contributions to add such support are most welcome

  2. LucaCappelletti94 commented on Sep 22, 2026

    @LucaCappelletti94
    Contributor

    Closing as completed in #1166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions