The TRUNCATE statement is used to remove all data from an existing table. This topic describes how to use the TRUNCATE statement in Hologres.
Limits
The
TRUNCATE
statement has the following limits:
- Hologres supports sequences. However, only CONTINUE IDENTITY is supported. RESTART IDENTITY is not supported.
- The
TRUNCATE
statement can be executed on a table and its child tables. - The
TRUNCATE
statement cannot be executed on a foreign table. - Only Hologres version 0.8 and later support the
TRUNCATE
statement. To obtain the latest version of Hologres, submit a ticket.
Syntax
The
TRUNCATE
statement has the following syntax:TRUNCATE [ TABLE ] name [, ... ]
[CONTINUE IDENTITY ]
The following table describes the parameters in the syntax.Parameter | Description |
---|---|
CONTINUE IDENTITY | Do not change the values of sequences.
Note Hologres supports only CONTINUE IDENTITY.
|
Example
This section describes the examples of the
TRUNCATE
statement.
- Example 1: Create a table named event. Import data to the table and query the data. Execute the
TRUNCATE TABLE event;
statement to remove all data from the event table. The following statements provide an example:CREATE TABLE event ( id int, name text, tag text ); INSERT INTO event (id,name,tag) values (23,'buy', 'num'); SELECT * FROM event; TRUNCATE TABLE event;
- Example 1: Create a table named \event_1. Import data to the table and query the data. Execute the
TRUNCATE TABLE event_1 CONTINUE IDENTITY;
statement to remove all data from the event_1 table without changing the values of sequences. The following statements provide an example:CREATE TABLE event_1 ( id serial, name text, tag text ); INSERT INTO event_1 (name,tag) values ('buy', 'num'); SELECT * FROM event_1; # CONTINUE IDENTITY is the default value TRUNCATE TABLE event_1 CONTINUE IDENTITY;
FAQ
- Issue
An
ERROR: TRUNCATE TABLE is not supported now.
error occurred when I executed theTRUNCATE TABLE <table name>;
statement. - Cause
The current Hologres version is too old.
- Solution
To obtain the latest version of Hologres, submit a ticket.