暂无图片
pg中子表的truncate问题
我来答
分享
暂无图片 匿名用户
pg中子表的truncate问题

truncate table only northamerica; 

truncate table northamerica;

有啥区别?测试没发现有啥不同的

northamerica 是父表的一个子分区

我来答
添加附件
收藏
分享
问题补充
2条回答
默认
最新
岳麓丹枫

示例

drop table if exist test;
drop table if exist test_2025_01_01;

create table test(id serial primary key, info text);
create table test_2025_01_01() inherits (test);
insert into test(info) values('info1');
insert into test_2025_01_01(info) values('info2');

postgres=# begin;
BEGIN
postgres=# truncate test;
TRUNCATE TABLE
postgres=# select * from test;
 id | info
----+------
(0 rows)

postgres=# select * from test_2025_01_01;
 id | info
----+------
(0 rows)

postgres=# rollback;
ROLLBACK
postgres=# begin;
BEGIN
postgres=# truncate only test;
TRUNCATE TABLE
postgres=# select * from test_2025_01_01;
 id | info
----+-------
  2 | info2
(1 row)

postgres=# select * from test;
 id | info
----+-------
  2 | info2
(1 row)

postgres=#
postgres=# select * from only test;
 id | info
----+------
(0 rows)

postgres=# rollback;
ROLLBACK
postgres=#
暂无图片 评论
暂无图片 有用 0
zzzdwd

only  是针对父表而言,如果是子表,是无所谓的关键字了,起不了什么作用。

暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏