如何在clickhouse中为数据库设置复合主键?

4zcjmb1e  于 2021-07-15  发布在  ClickHouse
关注(0)|答案(1)|浏览(905)

例如,我的模式是

host : String,
timestamp : Date,
comment: String

我想我的主键是主机,时间戳。

p8ekf7hl

p8ekf7hl1#

create table data(host String, timestamp Date, comment String) 
engine MergeTree order by (host, timestamp);

更新

这个 MergeTree 的主键与rdmbs的主键不同,因为它不保证唯一性。为了实现这一点,您可以研究这两种变体。
https://clickhouse.yandex/docs/en/operations/table_engines/replacingmergetree/
https://clickhouse.yandex/docs/en/operations/table_engines/collapsingmergetree/

相关问题