Updated on 2024-12-31 GMT+08:00

TRUNCATE TABLE

Syntax

TRUNCATE TABLE table_name

Description

This statement is used to remove all rows from a table or partition. When the table property auto.purge is set to the default value false, the deleted data rows will be saved in the file system's recycle bin. However, if auto.purge is set to true, the data rows will be directly deleted.

Remarks

The target table must be a control table, which means table propery external is set to false. Otherwise, an error will be reported during statement execution.

Example

-- Delete a native or control table
Create table simple(id int, name string);
 
Insert into simple values(1,'abc'),(2,'def');
 
select * from simple;
 id | name
----|------
  1 | abc
  2 | def
(2 rows)
 
Truncate table simple;
 
select * from simple;
 id | name
----|------
(0 rows)