当前位置:网站首页>Clickhouse column basic data type description

Clickhouse column basic data type description

2022-06-13 07:39:00 Letter brother blog

This article is about clickhouse Column 5 , For more information, please pay attention to this historical article !

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     │└─────────────────────────────────┴──────────────────┴─────────────┘

Two 、 Basic data type

clickhouse Just like traditional databases , Provides basic data types , This part is a brief introduction , 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;

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.

peer1 :)   select toFixedString('zimug', 6), length(toFixedString('zimug', 6));┌─toFixedString('zimug', 6)─┬─length(toFixedString('zimug', 6))─┐│ zimug                     │                                 6 │└───────────────────────────┴───────────────────────────────────┘

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');   

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 Same type , 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 》

原网站

版权声明
本文为[Letter brother blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130735114258.html