3 -- Check the LIMIT/OFFSET feature of SELECT
5 SELECT ''::text AS two, unique1, unique2, stringu1
6 FROM onek WHERE unique1 > 50
7 ORDER BY unique1 LIMIT 2;
8 two | unique1 | unique2 | stringu1
9 -----+---------+---------+----------
14 SELECT ''::text AS five, unique1, unique2, stringu1
15 FROM onek WHERE unique1 > 60
16 ORDER BY unique1 LIMIT 5;
17 five | unique1 | unique2 | stringu1
18 ------+---------+---------+----------
26 SELECT ''::text AS two, unique1, unique2, stringu1
27 FROM onek WHERE unique1 > 60 AND unique1 < 63
28 ORDER BY unique1 LIMIT 5;
29 two | unique1 | unique2 | stringu1
30 -----+---------+---------+----------
35 SELECT ''::text AS three, unique1, unique2, stringu1
36 FROM onek WHERE unique1 > 100
37 ORDER BY unique1 LIMIT 3 OFFSET 20;
38 three | unique1 | unique2 | stringu1
39 -------+---------+---------+----------
45 SELECT ''::text AS zero, unique1, unique2, stringu1
46 FROM onek WHERE unique1 < 50
47 ORDER BY unique1 DESC LIMIT 8 OFFSET 99;
48 zero | unique1 | unique2 | stringu1
49 ------+---------+---------+----------
52 SELECT ''::text AS eleven, unique1, unique2, stringu1
53 FROM onek WHERE unique1 < 50
54 ORDER BY unique1 DESC LIMIT 20 OFFSET 39;
55 eleven | unique1 | unique2 | stringu1
56 --------+---------+---------+----------
70 SELECT ''::text AS ten, unique1, unique2, stringu1
72 ORDER BY unique1 OFFSET 990;
73 ten | unique1 | unique2 | stringu1
74 -----+---------+---------+----------
87 SELECT ''::text AS five, unique1, unique2, stringu1
89 ORDER BY unique1 OFFSET 990 LIMIT 5;
90 five | unique1 | unique2 | stringu1
91 ------+---------+---------+----------
99 SELECT ''::text AS five, unique1, unique2, stringu1
101 ORDER BY unique1 LIMIT 5 OFFSET 900;
102 five | unique1 | unique2 | stringu1
103 ------+---------+---------+----------
111 -- Stress test for variable LIMIT in conjunction with bounded-heap sorting
114 FROM (VALUES (1)) AS x,
115 (SELECT n FROM generate_series(1,10) AS n
116 ORDER BY n LIMIT 1 OFFSET s-1) AS y) AS z
117 FROM generate_series(1,10) AS s;