This topic describes how to create a hash-range partitioned table.
Syntax
The following statement is used to create one or more hash-range partitioned table where each partition may contain one or more subpartitions:
CREATE TABLE [ schema. ]table_name
table_definition
PARTITION BY [LINEAR] HASH(expr)
SUBPARTITION BY RANGE (expr)
(partition_definition [, partition_definition] ...)
partition_definition
is:
PARTITION partition_name
(subpartition_definition [, subpartition_definition] ...)
subpartition_definition
is:
SUBPARTITION subpartition_name
VALUES LESS THAN {value | MAXVALUE}
Parameters
Parameter | Description |
table_name | The name of the table. |
expr | The expression of the partition. It must be of the INT type. The string type is not supported. |
value | The boundary value of the partition. |
MAXVALUE | The maximum value of the partition. |
partition_name | The name of the partition. The name must be unique within the table. |
subpartition_name | The name of the subpartition. The name must be unique within the table. |
Examples
Create a hash-range partitioned table:
CREATE TABLE sales_hash_range
(
dept_no INT,
part_no INT,
country varchar(20),
date DATE,
amount INT
)
PARTITION BY HASH(dept_no)
SUBPARTITION BY RANGE(part_no)
(
PARTITION p0 (
SUBPARTITION s0 VALUES LESS THAN(4),
SUBPARTITION s1 VALUES LESS THAN(7),
SUBPARTITION s2 VALUES LESS THAN(10),
SUBPARTITION s3 VALUES LESS THAN(13)
),
PARTITION p1
(
SUBPARTITION s4 VALUES LESS THAN(4),
SUBPARTITION s5 VALUES LESS THAN(7),
SUBPARTITION s6 VALUES LESS THAN(10),
SUBPARTITION s7 VALUES LESS THAN(13)
),
PARTITION p2
(
SUBPARTITION s8 VALUES LESS THAN(4),
SUBPARTITION s9 VALUES LESS THAN(7),
SUBPARTITION s10 VALUES LESS THAN(10),
SUBPARTITION s11 VALUES LESS THAN(13)
)
);