Clickhouse 在创建MergeTree引擎的表时,必须指定一些必要的参数,否则会报DB::Exception: Storage MergeTree requires 3 to 4 parameters的错误。
目录导航
报错样例
localhost :) create table t1(id int, name varchar(100),birthday date)ENGINE = MergeTree();
CREATE TABLE t1
(
`id` int,
`name` varchar(100),
`birthday` date
)
ENGINE = MergeTree
Query id: 6f3cbf90-2921-4eb8-b0e3-959b503bcb03
0 rows in set. Elapsed: 0.059 sec.
Received exception from server (version 21.4.5):
Code: 42. DB::Exception: Received from localhost:9000. DB::Exception: Storage MergeTree requires 3 to 4 parameters:
name of column with date,
[sampling element of primary key],
primary key expression,
index granularity
Syntax for the MergeTree table engine:
CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
(
name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1] [TTL expr1],
name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2] [TTL expr2],
...
INDEX index_name1 expr1 TYPE type1(...) GRANULARITY value1,
INDEX index_name2 expr2 TYPE type2(...) GRANULARITY value2
) ENGINE = MergeTree()
ORDER BY expr
[PARTITION BY expr]
[PRIMARY KEY expr]
[SAMPLE BY expr]
[TTL expr [DELETE|TO DISK 'xxx'|TO VOLUME 'xxx'], ...]
[SETTINGS name=value, ...]
See details in documentation: https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/mergetree/. Other engines of the family support different syntax, see details in the corresponding documentation topics.
If you use the Replicated version of engines, see https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/replication/.
.
解决方案
指定一些必要的参数,比如主键列 primary key
localhost :) create table t1(id int, name varchar(100),birthday date)ENGINE = MergeTree() primary key id;
CREATE TABLE t1
(
`id` int,
`name` varchar(100),
`birthday` date
)
ENGINE = MergeTree
PRIMARY KEY id
Query id: 5f8f94dc-3db7-429c-b954-32538c859095
Ok.
0 rows in set. Elapsed: 0.057 sec.
localhost :)