OFFSET
Note
To see which AWS data source integrations support this SQL command, see Supported OpenSearch SQL commands and functions.
The OFFSET
clause is used to specify the number of rows to skip
before beginning to return rows returned by the SELECT
statement. In general, this clause is used in conjunction with ORDER
BY
to ensure that the results are deterministic.
Syntax
OFFSET integer_expression
Parameters
integer_expression
Specifies a foldable expression that returns an integer.
Examples
CREATE TABLE person (name STRING, age INT); INSERT INTO person VALUES ('Jane Doe', 25), ('Pat C', 18), ('Nikki W', 16), ('Juan L', 25), ('John D', 18), ('Jorge S', 16); -- Skip the first two rows. SELECT name, age FROM person ORDER BY name OFFSET 2; +-------+---+ | name|age| +-------+---+ | John D| 18| | Juan L| 25| |Nikki W| 16| |Jane Doe| 25| +-------+---+ -- Skip the first two rows and returns the next three rows. SELECT name, age FROM person ORDER BY name LIMIT 3 OFFSET 2; +-------+---+ | name|age| +-------+---+ | John D| 18| | Juan L| 25| |Nikki W| 16| +-------+---+ -- A function expression as an input to OFFSET. SELECT name, age FROM person ORDER BY name OFFSET length('WAGON'); +-------+---+ | name|age| +-------+---+ |Jane Doe| 25| +-------+---+