首页 > 解决方案 > Postgres 12 中的列表分区

问题描述

CREATE TABLE countrymeasurements
(
  countrycode int NOT NULL,
  countryname character varying(30) NOT NULL,
  languagename character varying (30) NOT NULL,
  daysofoperation character varying(30) NOT NULL,
  salesparts    bigint,
  replaceparts  bigint
)
 PARTITION BY LIST(countrycode)
 (
  partition india values(1),
  partition japan values(2),
  partition china values(3),
  partition malaysia values(4)
  );

我收到错误:“(”或附近的语法错误。我在这里缺少什么。我正在使用 postgres12

标签: postgresqldatabase-partitioning

解决方案


我不知道您在哪里找到该语法,显然不在手册中。如您所见create table .. as partition of在 Postgres中创建了分区:

定义表:

CREATE TABLE countrymeasurements
(
  countrycode int NOT NULL,
  countryname character varying(30) NOT NULL,
  languagename character varying (30) NOT NULL,
  daysofoperation character varying(30) NOT NULL,
  salesparts    bigint,
  replaceparts  bigint
)
PARTITION BY LIST(countrycode);

定义分区:

create table india 
  partition of countrymeasurements 
  for values in (1);
  
create table japan
  partition of countrymeasurements 
  for values in (2);
  
create table china
  partition of countrymeasurements 
  for values in (3);

create table malaysia
  partition of countrymeasurements 
  for values in (4);

推荐阅读