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

Limited to blog space , I won't list more wonderful contents one by one , Recommended reading

《 Original boutique videos and supporting documents :springboot- Recorded 97 section ( free )》

Etc., etc.

【clickhouse special column 】 More related articles on basic data type descriptions

  1. [.net Fundamentals of object-oriented programming ] (3) The foundation in the foundation —— data type

    [.net Fundamentals of object-oriented programming ] (3) The foundation in the foundation —— data type About data types , This is the basis of the foundation . Basics .. Basics .. Basics . Basic skills must be solid . First , Start with the computer , And programming , Computers need to store data , Just by type ...

  2. TypeScript Chapter one of the study guide -- Basic data type (Basic Types)

    Basic data type (Basic Types) To build an application , We need to use some basic data types, such as :numbers,strings,structures,boolean wait . stay TypeScript In addition to Ja ...

  3. 【Swift】 Learning notes ( One )—— Well-known Basic data type , Encoding style , Tuples , opinion

    Since Apple announced swift after , I've always wanted to know , He has not been able to put it into formal study , Starting today , I will use my blog to drive swift hear , As far as we know, it will be soon . 1. Define variables and constants var   Defining variables ,let Define constants . such as ...

  4. Two 、Windows Basic data type

    6、 ... and .Windows Data Types brief introduction : 6.1. These data types are C The language data type is packaged again . 6.2. Because considering that if C The underlying data type in may not represent , The precise meaning you want to express . 6.3. ...

  5. java Basic data type, wrapper class

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  6. java.lang Basic data type boolean、char、byte、short、int、long、float、double (JDK1.8)

    java.lang.Boolean public static int hashCode(boolean value) { return value ? 1231 : 1237; } JDK 1.8 new ...

  7. Python List and tuples of basic data types

    One . list    list The list is python One of the basic data types in , There are also data types similar to lists in other languages , such as js Middle is called array , He is with [] Cover up , Each element is separated by commas , And it can store all kinds of data types, such as : li ...

  8. Python Dictionary of basic data types

      Dictionary of basic data types ps: Data type division : Variable data types and immutable data types . Immutable data types : Tuples (tupe). Boolean value (bool). Integer type (int). character string (str). Immutable data types are also called hashable . variable ...

  9. Python The collection of basic data types and other data types copy

    One . Basic data type summary supplement list  When looping through a list , It's best not to delete elements from the list , This will change the index , To report a mistake ( You can cycle back and forth to delete , This does not change the index of undeleted elements ). Error model : lis = [,,, ...

  10. python Foundation two ( Basic data type )

    One . Introduction 1. What is data x=10,10 It's the data we want to store 2. Why data should be classified into different types Data is used to represent states , Different states should be represented by different types of data 3. data type Numbers character string list Tuples word ...

Random recommendation

  1. Ubuntu14.04 lamp Environmental Science php Unable to load mcrypt Expand

    Ubuntu14.04 After installation in LAMP Environmental Science (http://www.cnblogs.com/daiyu/p/4380657.html) Not loaded in :mcrypt Expand , Later laravel5 Errors are reported during use ...

  2. Word2vec Model loading (tensorflow)

    opts = Options() with tf.Graph().as_default(), tf.Session() as session: model = Word2Vec(opts, sessi ...

  3. thinkPHP--SQL Inquire about

    One . A query ThinkPHP Three basic query methods are provided : String condition query . Index array condition query and object condition query . in the majority of cases , It is recommended to use index array and object mode as query criteria , Because it will be safer 1. Use a string as a bar ...

  4. from Mac Of Finder Visit your iCloud file

    [ from Mac Of Finder Visit your iCloud file ] from OS X 10.7.2 Start ,iCloud Just go deep Mac among , We can also do that Finder Access is stored in iCloud Documents in , Even when you have multiple Mac When ...

  5. There is only one difference between you and excellent source code Star

    fir.im Weekly - There is only one difference between you and excellent source code Star   Speaking of the open source community ,Github It's an indispensable existence . As the world's largest gay dating site , There are too many excellent open source code libraries and programming gods , Let countless developers ...

  6. TMS X-Cloud Todolist with FNC

    Wednesday, June 22, 2016 It's almost three months since we released the first version of the TMS FNC ...

  7. information_schema Introduction to pattern table processlist

    stay mysql in , We usually pass show (full)processlist Check the current connection , Dealing with all kinds of database problems . Now in information_schema In mode ,5.5 Later, it added processlist surface ...

  8. react For in the context The understanding of the

    One .context Basic use of the old version 1.context The understanding of the When you don't want to pass through layer by layer in the component tree props or state To transfer data , You can use context To achieve cross level component data transfer . 2.context Of ...

  9. VSCode The green version (zip Compressed package ) Add right click menu Use VSCode Open a file or folder

    Microsoft official download VSCode Can download exe In addition to installation, you can also download zip Compressed package Download address : https://code.visualstudio.com/Download however zip The compressed package is gone Right click to use VS ...

  10. [WC2014] Bauhinia love ( Dynamic point differentiation + Scapegoat thinking )

    Title Description Qiang Qiang and Meng Meng are good friends . One day they were hanging out , Suddenly I saw a bauhinia tree in front of me . It's the season for Bauhinia to fly , Countless petals grow out of the Bauhinia tree at the speed visible to the naked eye . If you take a closer look , This big tree is actually a power tree . Every time ...