All Products
Search
Document Center

PolarDB:Truncate a partition

Last Updated:May 17, 2024

PolarDB for PostgreSQL allows you to truncate a partition by performing similar operations to truncate a partitioned table. This topic describes the syntax for and provides an example on truncating a partition.

Syntax

TRUNCATE [ PARTITION ] name [ CASCADE | RESTRICT ]

You can use the TRUNCATE syntax to delete all rows from a group of partitioned tables. The TRUNCATE syntax is equivalent to the DELETE syntax performed on each table with no conditions specified. However, the TRUNCATE syntax does not scan partitioned tables. Therefore, the TRUNCATE syntax can delete data faster than the DELETE syntax.

After you execute the TRUNCATE statement to delete all rows from the partitioned tables, the system immediately defragments disks of the tables. Therefore, you do not need to perform subsequent VACUUM operations.

Example

Execute the following statement to truncate a partition named tab_range:

TRUNCATE tab_range;