首页 Clickhouse Mergetree Family
文章
取消

Clickhouse Mergetree Family

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- without ver - the last inserted 'wins'
CREATE TABLE IF NOT EXISTS myFirstReplacingMT
(
    `key` Int64,
    `someCol` String,
    `eventTime` DateTime
)
ENGINE = ReplacingMergeTree
PRIMARY KEY (key);

INSERT INTO myFirstReplacingMT Values (1, 'first', '2020-01-01 01:01:01');
INSERT INTO myFirstReplacingMT Values (1, 'second', '2020-01-01 00:00:00');

SELECT tuple(someCol) FROM myFirstReplacingMT FINAL;

-- 定义一个除了表引擎不同,其他部分完全与 myFirstReplacingMT 相同的表
CREATE TABLE IF NOT EXISTS mySecondReplacingMT
(
    `key` Int64,
    `someCol` String,
    `eventTime` DateTime
)
ENGINE = MergeTree
PRIMARY KEY (key);

-- 复制
ALTER TABLE mySecondReplacingMT ATTACH PARTITION tuple() FROM myFirstReplacingMT;
SELECT * FROM mySecondReplacingMT;

DROP TABLE myFirstReplacingMT SYNC;
-- DROP TABLE mySecondReplacingMT SYNC;
本文由作者按照 CC BY 4.0 进行授权

WSL 安装和使用简介

nushell 命令记录