当前位置:网站首页>Clickhouse column basic data type description
Clickhouse column basic data type description
2022-06-12 09:47:00 【51CTO】
This article is about clickhouse Column 5 , For more information, please pay attention to this historical article !
- One 、 Data type table
- Two 、 Basic data type
- Integer types
- Floating point type
- Decimal type
- Ordinary String type
- FixedString type
- UUID
- The date type
- Boolean type
One 、 Data type table
clickhouse Built in a lot of column data type , By querying system.data_type_families This table gets all the supported data types of the version . The first column below is the field type , The second column indicates whether the field type of this type is case sensitive (1 Indicates case insensitive ,Date and date Are valid data type names ), The third category is the alias of the field type .
peer1 :) SELECT * FROM system.data_type_families;
┌─name────────────────────────────┬─case_insensitive─┬─alias_to────┐
│ Polygon │ 0 │ │
│ Ring │ 0 │ │
│ Point │ 0 │ │
│ MultiPolygon │ 0 │ │
│ IPv6 │ 0 │ │
│ IntervalSecond │ 0 │ │
│ IPv4 │ 0 │ │
│ UInt32 │ 0 │ │
│ IntervalYear │ 0 │ │
│ IntervalQuarter │ 0 │ │
│ IntervalMonth │ 0 │ │
│ Int64 │ 0 │ │
│ IntervalDay │ 0 │ │
│ IntervalHour │ 0 │ │
│ UInt256 │ 0 │ │
│ Int16 │ 0 │ │
│ LowCardinality │ 0 │ │
│ AggregateFunction │ 0 │ │
│ Nothing │ 0 │ │
│ Decimal256 │ 1 │ │
│ Tuple │ 0 │ │
│ Array │ 0 │ │
│ Enum16 │ 0 │ │
│ IntervalMinute │ 0 │ │
│ FixedString │ 0 │ │
│ String │ 0 │ │
│ DateTime │ 1 │ │
│ Map │ 0 │ │
│ UUID │ 0 │ │
│ Decimal64 │ 1 │ │
│ Nullable │ 0 │ │
│ Enum │ 0 │ │
│ Int32 │ 0 │ │
│ UInt8 │ 0 │ │
│ Date │ 1 │ │
│ Decimal32 │ 1 │ │
│ UInt128 │ 0 │ │
│ Float64 │ 0 │ │
│ SimpleAggregateFunction │ 0 │ │
│ Nested │ 0 │ │
│ DateTime64 │ 1 │ │
│ Int128 │ 0 │ │
│ Decimal128 │ 1 │ │
│ Int8 │ 0 │ │
│ Decimal │ 1 │ │
│ Int256 │ 0 │ │
│ IntervalWeek │ 0 │ │
│ UInt64 │ 0 │ │
│ Enum8 │ 0 │ │
│ DateTime32 │ 1 │ │
│ UInt16 │ 0 │ │
│ Float32 │ 0 │ │
│ INET6 │ 1 │ IPv6 │
│ INET4 │ 1 │ IPv4 │
│ BINARY │ 1 │ FixedString │
│ NATIONAL CHAR VARYING │ 1 │ String │
│ BINARY VARYING │ 1 │ String │
│ NCHAR LARGE OBJECT │ 1 │ String │
│ NATIONAL CHARACTER VARYING │ 1 │ String │
│ NATIONAL CHARACTER LARGE OBJECT │ 1 │ String │
│ NATIONAL CHARACTER │ 1 │ String │
│ NATIONAL CHAR │ 1 │ String │
│ CHARACTER VARYING │ 1 │ String │
│ LONGBLOB │ 1 │ String │
│ MEDIUMTEXT │ 1 │ String │
│ TEXT │ 1 │ String │
│ TINYBLOB │ 1 │ String │
│ VARCHAR2 │ 1 │ String │
│ CHARACTER LARGE OBJECT │ 1 │ String │
│ DOUBLE PRECISION │ 1 │ Float64 │
│ LONGTEXT │ 1 │ String │
│ NVARCHAR │ 1 │ String │
│ INT1 UNSIGNED │ 1 │ UInt8 │
│ VARCHAR │ 1 │ String │
│ CHAR VARYING │ 1 │ String │
│ MEDIUMBLOB │ 1 │ String │
│ NCHAR │ 1 │ String │
│ CHAR │ 1 │ String │
│ SMALLINT UNSIGNED │ 1 │ UInt16 │
│ TIMESTAMP │ 1 │ DateTime │
│ FIXED │ 1 │ Decimal │
│ TINYTEXT │ 1 │ String │
│ NUMERIC │ 1 │ Decimal │
│ DEC │ 1 │ Decimal │
│ TINYINT UNSIGNED │ 1 │ UInt8 │
│ INTEGER UNSIGNED │ 1 │ UInt32 │
│ INT UNSIGNED │ 1 │ UInt32 │
│ CLOB │ 1 │ String │
│ MEDIUMINT UNSIGNED │ 1 │ UInt32 │
│ BOOL │ 1 │ Int8 │
│ SMALLINT │ 1 │ Int16 │
│ INTEGER SIGNED │ 1 │ Int32 │
│ NCHAR VARYING │ 1 │ String │
│ INT SIGNED │ 1 │ Int32 │
│ TINYINT SIGNED │ 1 │ Int8 │
│ BIGINT SIGNED │ 1 │ Int64 │
│ BINARY LARGE OBJECT │ 1 │ String │
│ SMALLINT SIGNED │ 1 │ Int16 │
│ MEDIUMINT │ 1 │ Int32 │
│ INTEGER │ 1 │ Int32 │
│ INT1 SIGNED │ 1 │ Int8 │
│ BIGINT UNSIGNED │ 1 │ UInt64 │
│ BYTEA │ 1 │ String │
│ INT │ 1 │ Int32 │
│ SINGLE │ 1 │ Float32 │
│ FLOAT │ 1 │ Float32 │
│ MEDIUMINT SIGNED │ 1 │ Int32 │
│ BOOLEAN │ 1 │ Int8 │
│ DOUBLE │ 1 │ Float64 │
│ INT1 │ 1 │ Int8 │
│ CHAR LARGE OBJECT │ 1 │ String │
│ TINYINT │ 1 │ Int8 │
│ BIGINT │ 1 │ Int64 │
│ CHARACTER │ 1 │ String │
│ BYTE │ 1 │ Int8 │
│ BLOB │ 1 │ String │
│ REAL │ 1 │ Float32 │
└─────────────────────────────────┴──────────────────┴─────────────┘
- 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.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
Two 、 Basic data type
clickhouse Just like traditional databases , Provides basic data types , This part is a brief introduction to , I believe that students who have learned programming languages are not unfamiliar with this part .
Integer types
Integer types ,IntN With N The increase of , The range of integer values is expanded .U Express unsigned Unsigned , No sign means no sign of negative numbers , Only storage greater than or equal to 0 The tree of .
- signed int (IntN):Int8、Int16、Int32、Int64、Int128、Int256. The range of values is 【-2^(N-1) ~ 2^(N-1)-1】, such as :Int8(-128 To 127)
- Unsigned integer (UIntN):UInt8、UInt16、UInt32、UInt64、UInt128、UInt256. The range of values is 【0 ~ 2^N-1】, such as :UInt8(0 To 255)
Floating point type
- Single-precision floating-point Float32, Did you learn C、java、mysql My friends regard it as float The data type can be used . After the decimal point 8 Bit start will cause a loss of precision .
- Double precision floating point Float64, Did you learn C、java、mysql My friends regard it as double The data type can be used . After the decimal point 17 Bit start will cause a loss of precision .
Decimal type
sometimes Float32、Float64 Can not meet the requirements of calculation accuracy , We need to use it Decimal data type .ClickHouse Provides Decimal32、Decimal64 and Decimal128 Three precision Decimal. When defining the types of table fields , There are two ways to declare : Abbreviations are Decimal32(S)、Decimal64(S)、Decimal128(S) Three , The native mode is Decimal(P, S), The maximum total length of integer bits plus decimal places of the fixed-point number is P, The maximum length of decimal places is S.
Refer to the following SQL And output results for understanding and learning
SELECT
toDecimal64(2, 3) AS x, -- Values for 2, Accuracy of 3, therefore 2.000
toTypeName(x) AS xtype,
toDecimal32(2, 2) AS y, -- Values for 2, Accuracy of 2, therefore 2.00
toTypeName(y) as ytype,
x + y AS a, --2.000 + 2.00, The addition and subtraction method takes the maximum accuracy . therefore 4.000
toTypeName(a) AS atype,
x * y AS b, --2.000*2.00, The precision values of multiplication are added (2+3=5). therefore 4.00000
toTypeName(b) AS btype,
x / y AS c, --2.000/2.00, Divisor 2.000 The accuracy is 3, The precision of the result is equal to the precision of the dividend . therefore 1.000
toTypeName(c) AS ctype;
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
The figure below shows the above SQL The results of the implementation of 
Ordinary String type
clickhouse Medium String Type has no length limit , So it can replace all the data types in the form of characters in the traditional relational database , Such as :CHAR、VARCHAR、CLOB wait .
FixedString type
FixedString(N) Indicates that the fixed length is N Data type of , have access to toFixedString Function will String convert to FixedString. In the following SQL although zimug The length is 5, But use FixedString(6) The length is 6, What is actually stored is zimug\0.
UUID
UUID Is a common unique data value ,ClickHouse Think of it as a data type .UUID The data format is as follows: :6fb875ae-75b9-4643-a146-5a1de7c717b4, Use as follows :
An example is as follows :
-- Create... When creating a table UUID Data type field
CREATE TABLE test_uuid (id UUID, content String) ENGINE=TinyLog;
-- Insert data into table
INSERT INTO test_uuid SELECT generateUUIDv4(), 'test uuid 1';
-- It is not inserted for UUID assignment ,UUID Fields use 0 fill
INSERT INTO test_uuid (content) VALUES ('test uuid 2');
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
The date type
There are three types of date data :DateTime、DateTime64 and Date, And support the use of strings insert Write date format . There is also a date type TIMESTAMP , How to use it and DateTime The type is exactly the same , Just for DateTime Data types are aliased .
- DateTime Accurate to seconds , Such as :'2022-06-12 06:06:06'
- DateTime64 Accurate to sub seconds , Such as :'2022-06-12 06:06:06.000'
- Date No time information , Accurate to the sky , Such as :'2022-06-12'
Boolean type
ClickHouse Boolean data type BOOLEAN . Its actual storage is the use of UInt8 type , The value is limited to 0 or 1.
Recommended reading
《clickhouse special column 》
边栏推荐
猜你喜欢

005: difference between data lake and data warehouse

传输层协议 ——— TCP协议

001:数据湖是什么?
What are the design principles of an automated test framework? I'll sum it up for you. Come and see

7-13 地下迷宫探索(邻接表)

Ceph性能优化与增强
What are the software testing requirements analysis methods? Let's have a look
Common omissions in software test reports, give yourself a wake-up call
![[cloud native | kubernetes] kubernetes networkpolicy](/img/8b/9260fc39d3f595cdc2689a3ab26bd7.png)
[cloud native | kubernetes] kubernetes networkpolicy
Share the basic knowledge of software testing and write something you don't know
随机推荐
Four steps for sending rockertmq producer messages
How CEPH improves storage performance and storage stability
anxious
Share the basic knowledge of software testing and write something you don't know
端午节安康--诸佬在我心里越来越粽要了
gnu-efi开发环境设置
自动化测试学习路线,快来学吧
Do you know how to improve software testing ability?
7-5 zhe zhe playing games
卖疯了的临期产品:超低价、大混战与新希望
Chained hash table
MySQL安装
What are the functions of resistance? (super full)
Mysql5.7 partition table
The white paper "protecting our digital heritage: DNA data storage" was released
QQ,微信能聊天都靠它(socket)?
MySQL优化之慢日志查询
网络层IP协议 ARP&ICMP&IGMP NAT
ThreadLocal
《保护我们的数字遗产:DNA数据存储》白皮书发布