Updated on 2025-03-13 GMT+08:00

Limit

Description

The limit operator limits the number of output execution results. If a limit operator is added, not all rows are retrieved.

Typical Scenarios

Use a query statement containing the keyword limit.

Examples

Example: Use a query statement containing the keyword limit.

-- Prepare data.
gaussdb=# CREATE TABLE t1 ( id int, number int);
CREATE TABLE 
gaussdb=# INSERT INTO t1 VALUES (generate_series(1,50), 1);
INSERT 0 50
gaussdb=# EXPLAIN SELECT * FROM t1 LIMIt 10 OFFSET 20;
                        QUERY PLAN                        
----------------------------------------------------------
 Limit  (cost=0.29..0.44 rows=10 width=8)
   ->  Seq Scan on t1  (cost=0.00..31.49 rows=10 width=8)
(2 rows)

-- Drop.
gaussdb=# DROP TABLE t1;