小编mos*_*evi的帖子

使用默认分区中已存在的值创建新的表分区

我有下表:

CREATE TABLE orders
(
  info_date  date,
  country_code  VARCHAR,
  order_total   int,
  CONSTRAINT orders_pk PRIMARY KEY (info_date, country_code)
) PARTITION BY LIST (country_code);

CREATE TABLE orders_def PARTITION OF orders DEFAULT;
Run Code Online (Sandbox Code Playgroud)

我插入一些行country_code 'foo',它们最终位于默认分区中。

一段时间后,我决定应该'foo'有自己的分区,我该怎么做?

根据文档:

如果存在 DEFAULT 分区,并且 DEFAULT 分区中存在任何行,否则它们将适合要添加的新分区,则无法添加新分区。


这是我的尝试

begin;
CREATE TEMP TABLE temp_table ON COMMIT DROP AS 
SELECT * FROM orders where country_code = 'foo';
DELETE FROM orders where country_code = 'foo';
CREATE TABLE orders_foo PARTITION OF orders FOR VALUES IN ('foo');
INSERT INTO …
Run Code Online (Sandbox Code Playgroud)

postgresql migration partitioning default-value postgresql-11

4
推荐指数
1
解决办法
2342
查看次数