Drop Partition
Function
Drop one or more partitions from a partitioned table. Both managed tables and OBS tables support using this command to drop partitions. For OBS tables, you can also use the specified filter condition to drop partitions for batch deletion based on conditions.
Syntax
ALTER TABLE [db_name.]table_name DROP [IF EXISTS] PARTITION partition_spec1 [, PARTITION partition_spec2, ...];
Parameters
| Parameter | Description |
|---|---|
| db_name | Optional. Database name, consisting of letters, digits, and underscores (_). It cannot be purely numeric and cannot start with an underscore. |
| table_name | Table name. Only letters, digits, and underscores (_) are allowed. It cannot be purely numeric and cannot start with an underscore. The matching rule is ^(?!_)(?![0-9]+$)[A-Za-z0-9_$]*$. Special characters must be enclosed in single quotes (''). |
| IF EXISTS | Optional keyword. When specified, no error is reported if the partition does not exist. It is silently skipped. |
| partition_spec | Partition specification, in the format (col1=val1, col2=val2, ...). If the partition has multiple fields, not all fields need to be included. All matching partitions will be dropped. |
Precautions
- The table from which partitions are to be dropped must already exist. Otherwise, an error will occur.
- The partition to be dropped must already exist. Otherwise, an error will occur. Add IF EXISTS to the statement to avoid this error.
- For OBS tables, dropping a partition only deletes the metadata. The data files in the OBS directory are not automatically deleted.
Example 1: Drop a Specific Partition
Drop the partition facultyNo=20, classNo=103 from the table student.
ALTER TABLE student DROP PARTITION (facultyNo=20, classNo=103);
Example 2: Drop a Partition Using IF EXISTS
Use IF EXISTS to avoid an error if the partition does not exist.
ALTER TABLE student DROP IF EXISTS PARTITION (facultyNo=99, classNo=999);
Example 3: Drop Multiple Partitions Simultaneously
Drop multiple partitions in a single statement.
ALTER TABLE student DROP IF EXISTS PARTITION (facultyNo=99, classNo=999), PARTITION (facultyNo=100, classNo=100);
Example 4: Drop a Partition from a Table in a Specified Database
Drop a partition from the table student in the database academy.
ALTER TABLE academy.student DROP IF EXISTS PARTITION (facultyNo=20, classNo=103);
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot