Postgresql

Postgres表分區“沒有為行找到關係“parsel_part”的分區”錯誤?

  • January 24, 2018

我正在嘗試使用 PostgreSQL 10 的新分區方法。我有一個包含 150 萬行的父表。我想在這個已經填充的表上創建分區。

我創建了一個 新的主表,它的列與CREATE SCRIPT 中的真實主表具有相同的列;

CREATE TABLE master_part (objectid integer,poly geometry(Geometry,2321), parcel character varying(255), m_date(date)) PARTITION BY RANGE (m_date);

然後我創建了由 m_date 列分區的子表;

CREATE TABLE parsel_2014_04
 PARTITION OF parsel_part FOR VALUES FROM ('2014-04-01') TO ('2014-04-30');

CREATE TABLE parsel_2014_05
     PARTITION OF parsel_part FOR VALUES FROM ('2014-05-01') TO ('2014-05-31');

CREATE TABLE parsel_2014_06
     PARTITION OF parsel_part FOR VALUES FROM ('2014-06-01') TO ('2014-06-30');

CREATE TABLE parsel_2014_07
     PARTITION OF parsel_part FOR VALUES FROM ('2014-07-01') TO ('2014-07-31');

CREATE TABLE parsel_2014_08
     PARTITION OF parsel_part FOR VALUES FROM ('2014-08-01') TO ('2014-08-31');

CREATE TABLE parsel_2014_09
     PARTITION OF parsel_part FOR VALUES FROM ('2014-09-01') TO ('2014-09-30');

CREATE TABLE parsel_2014_10
     PARTITION OF parsel_part FOR VALUES FROM ('2014-10-01') TO ('2014-10-30');

CREATE TABLE parsel_2014_11
     PARTITION OF parsel_part FOR VALUES FROM ('2014-11-01') TO ('2014-11-30');

CREATE TABLE parsel_2014_12
     PARTITION OF parsel_part FOR VALUES FROM ('2014-12-01') TO ('2014-12-31');

CREATE TABLE parsel_2015_01
     PARTITION OF parsel_part FOR VALUES FROM ('2015-01-01') TO ('2015-01-31');

CREATE TABLE parsel_2015_02
     PARTITION OF parsel_part FOR VALUES FROM ('2015-02-01') TO ('2015-02-28');

CREATE TABLE parsel_2015_03
     PARTITION OF parsel_part FOR VALUES FROM ('2015-03-01') TO ('2015-03-31');

CREATE TABLE parsel_2015_04
     PARTITION OF parsel_part FOR VALUES FROM ('2015-04-01') TO ('2015-04-30');

當我執行上面的腳本來創建子表時,出現以下錯誤;

錯誤:沒有為行找到關係“parsel_part”的分區詳細資訊:失敗行的分區鍵包含(m_date)=(2014-10-31)。SQL 狀態:23514

這個錯誤似乎非常罕見,因為我找不到任何關於它的資訊。

也許有人以前見過它?

您的問題與文件中的這一點有關:

創建範圍分區時,用指定的下限FROM包含邊界,而用指定的上限TO 是排除邊界

(重點補充)

所以實際上在

CREATE TABLE parsel_2014_10 PARTITION OF parsel_part 
    FOR VALUES FROM ('2014-10-01') TO ('2014-10-31');

該日期2014-10-31不包含在此分區中,因此在所有分區表中都沒有(並且所有結束日期都相同**)**

請參閱以下範例:https ://www.postgresql.org/docs/10/static/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE

一個分區的to值必須與下一個分區的from值相同(因為該to部分是獨占的,而該部分from是包含的)。

引用自:https://dba.stackexchange.com/questions/196134