10.3.12 TRUNCATE TABLE

Table of Contents Previous Next



Use the TRUNCATE TABLE command to remove the contents of a table, while preserving the table definition. When you truncate a table, any partitions or subpartitions of that table are also truncated. The syntax is:
TRUNCATE TABLE table_name
The TRUNCATE TABLE command removes an entire table, and the data that resides in that table. When you delete a table, any partitions or subpartitions (of that table) are deleted as well.
To use the TRUNCATE TABLE command, you must be the owner of the partitioning root, a member of a group that owns the table, the schema owner, or a database superuser.
The example that follows removes the data from the sales table. Use the following command to create the sales table:
Populate the sales table with the command:
Querying the sales table shows that the partitions are populated with data:
To delete the contents of the sales table, invoke the following command:
Now, querying the sales table shows that the data has been removed but the structure is intact:
For more information about the TRUNCATE TABLE command, please see the PostgreSQL documentation at:


Table of Contents Previous Next