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=# 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=0.00..0.00 rows=1 width=8)
   ->  Data Node Scan on "__REMOTE_LIMIT_QUERY__"  (cost=0.00..0.00 rows=1 width=8)
         Node/s: All datanodes
(3 rows)

-- Drop.
gaussdb=# DROP TABLE t1;