mydb=> /d table_fenqu Table "skytf.table_fenqu" Column | Type | Modifiers ---------+-----------------------------+----------- id | integer | addtime | timestamp without time zone | Number of child tables: 3 (Use d+ to list them.)
mydb=> select count(*) from table_fenqu; count ------- 5 (1 row)
mydb=> truncate table only table_fenqu; TRUNCATE TABLE
mydb=> select count(*) from table_fenqu; count ------- 4 (1 row)
这里可以看出,加only时,只清空父表的一条数据,而子表的数据保留着。
1 2 3 4 5
mydb=> select count(*) from only table_fenqu; count ------- 0 (1 row)
Truncate 语法官方文档
Name TRUNCATE ― empty a table or set of tables Synopsis TRUNCATE [ TABLE ] [ ONLY ] name [, … ] [ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]
name The name (optionally schema-qualified) of a table to be truncated. If ONLY is specified, only that table is truncated. If ONLY is not specified, the table and all its descendant tables (if any) are truncated.