All Products
Search
Document Center

PolarDB:TRUNCATE PARTITION

Last Updated:Jan 11, 2024

This topic describes how to delete all data from a specified subpartition and retain the complete schema of the subpartition.

Syntax

The ALTER TABLE…TRUNCATE PARTITION statement is used to delete all data from a specified subpartition and retain the complete schema of the subpartition.
ALTER TABLE table_name
  TRUNCATE PARTITION partition_name [,partition_name] ...
Note If you execute this statement on a table that contains subpartitions and specify the partition name, the data stored in the subpartitions of the specified partition is deleted.
partition_name is:
{partition_name | subpartition_name}

Parameters

ParameterDescription
table_nameThe name (optionally schema-qualified) of the partitioned table.
partition_nameThe name of the partition.
subpartition_nameThe name of the subpartition.

Examples

Delete the data from the p5 partition and the q1_2012 subpartition in the sales_range_list partitioned table:
ALTER TABLE sales_range_list TRUNCATE PARTITION q1_2012,p5;
Delete the data from the p5 subpartition in the sales_range_list partitioned table:
ALTER TABLE sales_range_list TRUNCATE PARTITION p5;