Skip to content

Not possible to specify window specification in the absence of ORDER BY clause #869

@sivaraam

Description

@sivaraam

Describe the bug

In Postgres and MySQL, it is possible to specify a window specification (ROWS/RANGE ...) without an ORDER BY clause for window functions. But the parser requires the ORDER BY clause to be present before the window specification.

Reference

To Reproduce

Steps to reproduce the behavior:

  1. Example SQL
select subject_id, student_id, mark, sum(mark) over (partition by (subject_id) rows between unbounded preceding and current row) from marks
  1. Parsing this SQL using JSqlParser with this statements
        try {
            Statement st = CCJSqlParserUtil.parse("select subject_id, student_id, mark, sum(mark) over (partition by (subject_id) rows between unbounded preceding and current row) from marks");
        }
        catch (JSQLParserException jsqle) {
            jsqle.printStackTrace();

        }
  1. Exception
net.sf.jsqlparser.JSQLParserException
	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:51)
...
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "rows" "ROWS"
    at line 1, column 80.

Was expecting one of:

    "&"
    ")"
    ","
    "::"
    "<<"
    ">>"
    "COLLATE"
    "ORDER"
    "["
    "^"
    "|"

Expected behavior

It should be possible to specify window without the ORDER BY clause.

System

  • Database you are using: Postgres, MySQL
  • Java Version: 11.0.3
  • JSqlParser version: 3.0

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