TRUNCATE
Synopsis
Use the TRUNCATE statement to clear all rows in a table.
Syntax
truncate ::= TRUNCATE [ TABLE ] { { [ ONLY ] name [ * ] } [ , ... ] }
truncate
Semantics
truncate
TRUNCATE [ TABLE ] { { [ ONLY ] name [ * ] } [ , ... ] }
name
Specify the name of the table to be truncated.
TRUNCATEacquiresACCESS EXCLUSIVElock on the tables to be truncated. TheACCESS EXCLUSIVElocking option is not yet fully supported.TRUNCATEis not supported for foreign tables.
Examples
yugabyte=# CREATE TABLE sample(k1 int, k2 int, v1 int, v2 text, PRIMARY KEY (k1, k2));
yugabyte=# INSERT INTO sample VALUES (1, 2.0, 3, 'a'), (2, 3.0, 4, 'b'), (3, 4.0, 5, 'c');
yugabyte=# SELECT * FROM sample ORDER BY k1;
k1 | k2 | v1 | v2
----+----+----+----
1 | 2 | 3 | a
2 | 3 | 4 | b
3 | 4 | 5 | c
(3 rows)
yugabyte=# TRUNCATE sample;
yugabyte=# SELECT * FROM sample;
k1 | k2 | v1 | v2
----+----+----+----
(0 rows)