Updated on 2025-09-22 GMT+08:00

Partition Queries

Queries data in a specified partition.

The following example is a typical partition query, demonstrating how to partition a specified table and query information of a designated partition:

-- Create a range partitioned table.
gaussdb=#CREATE TABLE test_range1(
    id INT, 
    info VARCHAR(20)
) PARTITION BY RANGE (id) (
    PARTITION p1 VALUES LESS THAN (200),
    PARTITION p2 VALUES LESS THAN (400),
    PARTITION p3 VALUES LESS THAN (600),
    PARTITION p4 VALUES LESS THAN (800),
    PARTITION pmax VALUES LESS THAN (MAXVALUE)
);

-- Insert 1000 data records.
gaussdb=#INSERT INTO test_range1 VALUES(GENERATE_SERIES(1,1000),'abcd');

-- Query the number of data records in the p1 partition.
gaussdb=#SELECT COUNT(*) FROM test_range1 PARTITION (p1);
 count 
-------
   199
(1 row)

-- Drop.
gaussdb=#DROP TABLE test_range1;