Updated on 2025-05-29 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

Use a query statement containing the keyword limit.

-- Prepare data.
gaussdb=#DROP TABLE IF EXISTS t1;
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=11.23..15.89 rows=9 width=8)
   ->  Streaming (type: GATHER)  (cost=0.88..15.89 rows=9 width=8)
         Node/s: All datanodes
         ->  Limit  (cost=0.00..14.14 rows=29 width=8)
               ->  Seq Scan on t1  (cost=0.00..14.14 rows=29 width=8)
(5 rows)

-- Drop.
gaussdb=#DROP TABLE t1;

In the preceding example, the output of the Limit operator is as follows.

Item

Description

Limit

Operator name.

Seq Scan

Name of an operator that scans the t1 table in sequence.