question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for FETCH/OFFSET syntax

See original GitHub issue

In terms of syntax, this is what the spec says:

A <query expression> can also optionally contain a <result offset clause>, 
which may limit the cardinality of the derived table by removing a specified 
number of rows from the beginning of the derived table. If a <query expression> 
contains both an <order by clause> and a <result offset clause>, then the rows 
in the derived table are first sorted according to the <order by clause> and then
 limited by dropping the number of rows specified in the <result offset clause> 
from the beginning of the result produced by the <query expression>. If the 
cardinality of the result of an evaluation of a <query expression> is less than
 the offset value specified by a <result offset clause>, then the derived table is empty.

And

<query expression> ::=
  [ <with clause> ] <query expression body>
      [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]

<result offset clause> ::=
  OFFSET <offset row count> { ROW | ROWS }

<fetch first clause> ::=
  FETCH { FIRST | NEXT } [ <fetch first quantity> ] { ROW | ROWS } { ONLY | WITH TIES }

<fetch first quantity> ::=
    <fetch first row count>
  | <fetch first percentage>

<offset row count> ::=
  <simple value specification>

<fetch first row count> ::=
  <simple value specification>

<fetch first percentage> ::=
  <simple value specification> PERCENT

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
martintcommented, Apr 22, 2019

Do we want to support simplified syntax OFFSET n LIMIT m as well?

Yes, that would fall out naturally from having LIMIT be an alternate form of FETCH FIRST/NEXT.

Do we want to support LIMIT m OFFSET n version too. It is misleading […]

Agreed. That’s confusing. Let’s not add it for now. We can always expand later.

0reactions
arminmaurice1990commented, Jan 14, 2020

https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax As above, the syntax is almost fully interchangeable for non-trivial queries, save for the ordering of limit and offset (offset being part of the limit clause, same with Postgres syntax https://www.postgresql.org/docs/8.1/queries-limit.html which I know presto already translates to).

edit: seems as though this is standard with impala as well http://impala.apache.org/docs/build/html/topics/impala_offset.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add support for FETCH/OFFSET syntax · Issue #1 · trinodb/trino
Do we want to support simplified syntax OFFSET n LIMIT m as well? Yes, that would fall out naturally from having LIMIT be...
Read more >
SQL Server OFFSET FETCH: Limit The Number of Rows ...
In this syntax: The OFFSET clause specifies the number of rows to skip before starting to return rows from the query. The offset_row_count...
Read more >
fetchOffset | Apple Developer Documentation
This setting allows you to specify an offset at which rows will begin being returned. Effectively, the request skips the specified number of...
Read more >
SQL | OFFSET-FETCH Clause - GeeksforGeeks
Syntax : SELECT column_name(s) FROM table_name ORDER BY ... See your article appearing on the GeeksforGeeks main page and help other Geeks.
Read more >
Error while using FETCH/OFFSET fucntion in SQL
You have to use LIMIT instead of FETCH NEXT rows as it is not MySQL syntax. Also go through the following link where...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found