更新日期:2024年09月11日
TRUNCATE HIVE PARTITION
语法格式
TRUNCATE TABLE [database_name.]table_name PARTITION partition_spec;
参数说明
database_name:可选参数,表示表隶属的数据库名称。如果省略此参数,即为
USE 后的数据库名称。
table_name:是要执行的表的名称。
Partition_spec:是要删除的分区的名称。
功能
TRUNCATE TABLE 删除分区中的所有行,
但该分区保持不变。
适用于Hive 引擎的
分区表。
示例
示例1:
GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 653
gbase> create table hp2(a int,b int) partitioned by (c int) engine=hive;
Query OK, 0 rows affected
gbase> insert into hp2 partition (c = 100) values (10,20);
Query OK, 1 row affected
gbase> select * from hp2;
+------+------+------+
| a | b | c |
+------+------+------+
| 10 | 20 | 100 |
+------+------+------+
1 row in set
gbase> show partitions from hp2;
+-----------+
| partition |
+-----------+
| c=100 |
+-----------+
1 row in set
gbase> create table hp2(a int,b int) partitioned by (c int) engine=hive;
Query OK, 0 rows affected
gbase> insert into hp2 partition (c = 100) values (10,20);
Query OK, 1 row affected
gbase> select * from hp2;
+------+------+------+
| a | b | c |
+------+------+------+
| 10 | 20 | 100 |
+------+------+------+
1 row in set
gbase> show partitions from hp2;
+-----------+
| partition |
+-----------+
| c=100 |
+-----------+
1 row in set
gbase> truncate table hp2 partition(c=100);
Query OK
gbase> show partitions from hp2;
+-----------+
| partition |
+-----------+
| c=100 |
GBase UP 产品手册 5 数据库管理指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 654