This topic describes how to create a list-hash partitioned table.
Syntax
The following statement is used to create one or more list-hash partitioned tables. Partitions are of the LIST [COLUMNS] type. Subpartitions are of the HASH or KEY type.
CREATE TABLE [ schema. ]table_name
table_definition
PARTITION BY LIST {(expr) COLUMNS(column_list)}
SUBPARTITION BY {[LINEAR] HASH(expr) [SUBPARTITIONS number]
[LINEAR] KEY [ALGORITHM={1 2}] (column_list)}
(partition_definition [, partition_definition] ...);
partition_definition is:
PARTITION partition_name
VALUES IN ( value_list)
(subpartition_definition [, subpartition_definition] ...)
partition_definition is:
SUBPARTITION subpartition_name
Parameters
Parameter | Description |
expr | The expression of the partition. It must be of the INT type. The string type is not supported. |
number | The number of subpartitions. |
column_list | The list of partition key columns. Expressions are not supported. |
value_list | The list of the boundary values of the partitions. |
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 list-hash partitioned table:
CREATE TABLE sales_list_hash
(
dept_no INT,
part_no INT,
country varchar(20),
date DATE,
amount INT
)
PARTITION BY LIST(amount)
SUBPARTITION BY HASH(dept_no) SUBPARTITIONS 2
(
PARTITION p0 VALUES in (1, 2),
PARTITION p1 VALUES in (3, 4),
PARTITION p2 VALUES in (5, 6)
);
Create a list columns-hash partitioned table:
CREATE TABLE sales_list_columns_hash
(
dept_no INT,
part_no INT,
country varchar(20),
date DATE,
amount INT
)
PARTITION BY LIST COLUMNS(country)
SUBPARTITION BY HASH(dept_no) SUBPARTITION 2
(
PARTITION europe VALUES in ('FRANCE', 'ITALY'),
PARTITION asia VALUES in ('INDIA', 'PAKISTAN'),
PARTITION americas VALUES in ('US', 'CANADA')
);