无法删除主表数据 postgresql



我有一个包含数据的现有表。

create table work_data(
id  integer not null,
work_time timestamp(3) without time zone not null,
message character varying(64),
primary key (id)
);

我把桌子隔开了。

create table w_work01(
constraint pk_01 primary key (id),
constraint ck_01
check (work_time >= '2019/07/01'::date and work_time < '2019/07/02'::date)
) inherits (work_data);
create index idx_01 on w_work01 (work_time);

并将数据从work_data插入到w_work01。

insert into w_work01
select * from work_data
where work_time >= '2019/07/01'::date and work_time < '2019/07/02'::date)

然后删除了分区表。

DROP TABLE w_work01;

已删除分区表。 但主表中的数据保持不变。 所以我搜索并找到了下面的查询。

ALTER TABLE master_table DROP PARTITION partitioned_table;

但是当我使用它时,出现了一个错误。

语法错误在 partitioned_table 或接近

我该如何解决?

您从未从work_data中删除数据,因此它仍然存在也就不足为奇了。你创建了一个表,填满它,然后放下它,这会产生什么净效果。

此外,您使用了表继承,而不是分区。

要对现有表进行排序,一种可能的方法是:

  • 创建一个类似work_data的表,但使用

    PARTITION BY RANGE (work_time)
    
  • 为所需范围创建分区

  • 将数据复制到分区表中,就像您在问题中所做的那样

  • 删除原始表

最新更新