Skip to content

Commit

Permalink
Allow simplified OFFSET syntax
Browse files Browse the repository at this point in the history
This change allows using simplified syntax
`OFFSET x`
instead of
`OFFSET x ROW/ROWS`
  • Loading branch information
kasiafi authored and martint committed May 11, 2019
1 parent 09759d2 commit aab267e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ property
queryNoWith:
queryTerm
(ORDER BY sortItem (',' sortItem)*)?
(OFFSET offset=INTEGER_VALUE (ROW | ROWS))?
(OFFSET offset=INTEGER_VALUE (ROW | ROWS)?)?
((LIMIT limit=(INTEGER_VALUE | ALL)) | (FETCH (FIRST | NEXT) (fetchFirst=INTEGER_VALUE)? (ROW | ROWS) ONLY))?
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,22 @@ public void testSelectWithOffset()
Optional.empty(),
Optional.empty()));

assertStatement("SELECT * FROM table1 OFFSET 2",
new Query(
Optional.empty(),
new QuerySpecification(
selectList(new AllColumns()),
Optional.of(new Table(QualifiedName.of("table1"))),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(new Offset("2")),
Optional.empty()),
Optional.empty(),
Optional.empty(),
Optional.empty()));

Query valuesQuery = query(values(
row(new LongLiteral("1"), new StringLiteral("1")),
row(new LongLiteral("2"), new StringLiteral("2"))));
Expand All @@ -959,6 +975,16 @@ public void testSelectWithOffset()
Optional.empty(),
Optional.of(new Offset("2")),
Optional.empty()));

assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) OFFSET 2",
simpleQuery(selectList(new AllColumns()),
subquery(valuesQuery),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.of(new Offset("2")),
Optional.empty()));
}

@Test
Expand Down

0 comments on commit aab267e

Please sign in to comment.