| 最小结构 | CREATE TABLE t (…) ENGINE = MergeTree ORDER BY (…) |
|---|---|
| 可选子句 | PARTITION BY、PRIMARY KEY、SAMPLE BY、TTL、SETTINGS、COMMENT |
| 列定义 | 名称 类型 [DEFAULT|MATERIALIZED|ALIAS 表达式] [CODEC(...)] [COMMENT ...] |
示例
示例
CREATE TABLE IF NOT EXISTS analytics.events
(
event_time DateTime,
event_date Date DEFAULT toDate(event_time),
user_id UInt64,
event_type LowCardinality(String),
props String CODEC(ZSTD(3))
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(event_time)
ORDER BY (event_type, user_id, event_time)
SETTINGS index_granularity = 8192;也可以用 CREATE TABLE t AS other_table 复制结构(ENGINE 同名复制),或 AS SELECT 建表并灌数据。