Truncate

Empties the contents of a table.

Synopsis

TRUNCATE [ TABLE ] name

Parameters

name

The name of the table you wish to truncate. To truncate a table means to remove all rows from the table.

Results

TRUNCATE

The message returned if the specified table is successfully truncated.

ERROR: Relation 'name' does not exist

The error returned if the specified table name does not exist in the connected database.

Description

Use this command to remove all rows of a specified table. It does not scan through the table before removing data, making it rather helpful when emptying large tables of data. In essence, it is a quicker form of the DELETE command.

Example

This example empties all of the rows in the temp_emp table:

booktown=# TRUNCATE TABLE temp_emp;
TRUNCATE

Get Practical PostgreSQL now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.