2 7.6. LIMIT and OFFSET #
4 LIMIT and OFFSET allow you to retrieve just a portion of the rows that
5 are generated by the rest of the query:
9 [ LIMIT { count | ALL } ]
12 If a limit count is given, no more than that many rows will be returned
13 (but possibly fewer, if the query itself yields fewer rows). LIMIT ALL
14 is the same as omitting the LIMIT clause, as is LIMIT with a NULL
17 OFFSET says to skip that many rows before beginning to return rows.
18 OFFSET 0 is the same as omitting the OFFSET clause, as is OFFSET with a
21 If both OFFSET and LIMIT appear, then OFFSET rows are skipped before
22 starting to count the LIMIT rows that are returned.
24 When using LIMIT, it is important to use an ORDER BY clause that
25 constrains the result rows into a unique order. Otherwise you will get
26 an unpredictable subset of the query's rows. You might be asking for
27 the tenth through twentieth rows, but tenth through twentieth in what
28 ordering? The ordering is unknown, unless you specified ORDER BY.
30 The query optimizer takes LIMIT into account when generating query
31 plans, so you are very likely to get different plans (yielding
32 different row orders) depending on what you give for LIMIT and OFFSET.
33 Thus, using different LIMIT/OFFSET values to select different subsets
34 of a query result will give inconsistent results unless you enforce a
35 predictable result ordering with ORDER BY. This is not a bug; it is an
36 inherent consequence of the fact that SQL does not promise to deliver
37 the results of a query in any particular order unless ORDER BY is used
38 to constrain the order.
40 The rows skipped by an OFFSET clause still have to be computed inside
41 the server; therefore a large OFFSET might be inefficient.