Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

OFFSET clause

The OFFSET clause skips a number of rows before returning the remaining rows.

Syntax

offset_clause
OFFSET SKIP number_of_rows_to_skip

offset_clause ::=
    ( 'OFFSET' | 'SKIP' ) number_of_rows_to_skip

Parameters

OFFSET | SKIP

The keyword that declares an OFFSET clause. They are equivalent and interchangeable.

number_of_rows_to_skip

A non-negative integer indicating the number of rows to be skipped. If it is greater than or equal to the total number of rows, no row is returned.

Examples

Skip rows when the number is smaller than the total number of rows

'''
TABLE users TYPED TABLE {id INT, name STRING} =
    (199, "Julie Kavner"),
    (198, "Tom Cruise"),
    (197, "Amy Hasegawa")
FOR r IN users
OFFSET 1
RETURN r.id AS id, r.name AS name
'''

The preceding statement skips the first row and returns the remaining rows, starting from the second row.

Return:

+-----+--------------+
| id  | name         |
+-----+--------------+
| 198 | Tom Cruise   |
| 197 | Amy Hasegawa |
+-----+--------------+

Skip rows when the number exceeds the total number of rows

If the number to skip exceeds the total number of rows, no rows are returned.

'''
TABLE users TYPED TABLE {id INT, name STRING} =
    (199, "Julie Kavner"),
    (198, "Tom Cruise"),
    (197, "Amy Hasegawa")
FOR r IN users
OFFSET 10
RETURN r.id AS id, r.name AS name
'''

The preceding statement has only 3 rows in total, so the result is empty after skipping 10 rows.

Return:

+----+------+
| id | name |
+----+------+
+----+------+