There is no OFFSET support in AWS Athena, but we can use a workaround to get the same behavior.
Table of Contents
Let’s assume that I want to execute this query:
SELECT * FROM some_table
ORDER BY column_A
OFFSET 20 LIMIT 10 -- this doesn't work
to get the desired outcome, I need three things:
- a window function that assigns a number to every row
- ordering method that sorts the table, so I get a deterministic outcome
- filtering function that selects only the rows I want
SELECT * FROM (
SELECT row_number() over(ORDER BY column_A) AS rn, * FROM some_table)
WHERE rn BETWEEN 20 AND 30; -- 30 = 20 (offset) + 10 (limit)
Get Weekly AI Implementation Insights
Join engineering leaders who receive my analysis of common AI production failures and how to prevent them. No fluff, just actionable techniques.