文章目录
注意
ck中关键字区分大小写
基本数据类型
整数
正整数和负整数 IntX
Int8(1个字节)【-128~127】、Int16、Int32、Int64
正整数 UIntX
UInt8(1个 字节)【0~255】、UInt16、UInt32、UInt64
小数
FloatX
Float64(DOUBLE)、Float32(FLOAT)
不管是Float32,还是Float64都有可能存在精度不准的问问题,所以建议使用Decimal
Decimal(X,Y)
X:指的是总位数
Y:共有几位小数
例如 Decimal(5,2) =》 666.77
字符串
String
UUID
一般结合系统函数 generateUUIDv4()使用
时间类型
年月日Date、年月日时分秒DateTime、年月日时分秒亚秒DateTime64
DateTime64(3)=DateTime64
create table test_date(
id Int8,
dt Date,
ctime DateTime,
ctimeplus DateTime64
)engine = MergeTree();
insert into test_date values (1,now(),now(),now());
select * from test_date;
复合数据类型
枚举
数组
元组 Tuple
create table test_tuple(
wc Tuple(String,UInt8)
)engine = MergeTree();
insert into test_tuple values (('java',3)),(tuple('flink',5));
select * from test_tuple;
映射 Map
SET allow_experimental_map_type=1;
CREATE TABLE test_map
(
id UInt32,
name String,
infomation Map(String, Int32)
) ENGINE = MergeTree()
ORDER BY id;
INSERT INTO test_map (id, name, infomation)
VALUES (1, 'Alice', {'age': 25, 'height': 170}),
(2, 'Bob', {'age': 30, 'height': 180});
SELECT *
FROM test_map;
嵌套结构 Nested
create table test_nested
(
id Int8,
name String,
scores Nested (
number UInt8 , -- 第几次考试
chinese Float64,
math Float64,
english Float64)
)
engine = MergeTree();
insert into test_nested values (1, 'zs',[1,2,3],[77,77,77],[88,88,88],[99,99,99]);
insert into test_nested values (1, 'ls',[1,2,3],[11,11,11],[22,22,22],[99,99,99]);
select * from test_nested;
IPv4 数据类型
CREATE TABLE test_table
(
id UInt32,
name String,
ip IPv4
) ENGINE = MergeTree()
ORDER BY id;
INSERT INTO test_table (id, name, ip)
VALUES (1, 'Alice', '192.168.0.1'),
(2, 'Bob', '10.0.0.1');
SELECT *
FROM test_table;