| PostgreSQL 7.4.30 Documentation | ||||
|---|---|---|---|---|
| Prev | Fast Backward | Fast Forward | Next | |
TRUNCATE quickly removes all rows from a table. It has the same effect as an unqualified DELETE but since it does not actually scan the table it is faster. This is most useful on large tables.
Only the owner of a table may TRUNCATE it.
TRUNCATE cannot be used if there are foreign-key references to the table from other tables. Checking validity in such cases would require table scans, and the whole point is not to do one.
TRUNCATE will not run any user-defined ON DELETE triggers that might exist for the table.
1:Tx - transaction;
2:T1 - begin;
3:T2 - select * from t1; => it returns rows;
4:T1 - truncate t1;
5:T2 - select * from t1; => it waits for commit(like lock table);
6:T1 - insert into t1 values(1);
7:T2 - commit;
just now T1 returns the rows added on line 6.