Data Types Overview

MatrixOne Data types conforms with MySQL Data types definition.

Reference: https://dev.mysql.com/doc/refman/8.0/en/data-types.html

Integer Numbers

Data TypeSizeMin ValueMax Value
TINYINT1 byte-128127
SMALLINT2 bytes-3276832767
INT4 bytes-21474836482147483647
BIGINT8 bytes-92233720368547758089223372036854775807
TINYINT UNSIGNED1 byte0255
SMALLINT UNSIGNED2 bytes065535
INT UNSIGNED4 bytes04294967295
BIGINT UNSIGNED8 bytes018446744073709551615

Examples

  • TINYINT and TINYINT UNSIGNED
  1. -- Create a table named "inttable" with 2 attributes of a "tinyint", a "tinyint unsigned",
  2. create table inttable ( a tinyint not null default 1, tinyint8 tinyint unsigned primary key);
  3. insert into inttable (tinyint8) values (0),(255), (0xFE), (253);
  4. mysql> select * from inttable order by 2 asc;
  5. +------+----------+
  6. | a | tinyint8 |
  7. +------+----------+
  8. | 1 | 0 |
  9. | 1 | 253 |
  10. | 1 | 254 |
  11. | 1 | 255 |
  12. +------+----------+
  13. 4 rows in set (0.03 sec)
  • SMALLINT and SMALLINT UNSIGNED
  1. -- Create a table named "inttable" with 2 attributes of a "smallint", a "smallint unsigned",
  2. drop table inttable;
  3. create table inttable ( a smallint not null default 1, smallint16 smallint unsigned);
  4. insert into inttable (smallint16) values (0),(65535), (0xFFFE), (65534), (65533);
  5. mysql> select * from inttable;
  6. +------+------------+
  7. | a | smallint16 |
  8. +------+------------+
  9. | 1 | 0 |
  10. | 1 | 65535 |
  11. | 1 | 65534 |
  12. | 1 | 65534 |
  13. | 1 | 65533 |
  14. +------+------------+
  15. 5 rows in set (0.01 sec)
  • INT and INT UNSIGNED
  1. -- Create a table named "inttable" with 2 attributes of a "int", a "int unsigned",
  2. drop table inttable;
  3. create table inttable ( a int not null default 1, int32 int unsigned primary key);
  4. insert into inttable (int32) values (0),(4294967295), (0xFFFFFFFE), (4294967293), (4294967291);
  5. mysql> select * from inttable order by a desc, 2 asc;
  6. +------+------------+
  7. | a | int32 |
  8. +------+------------+
  9. | 1 | 0 |
  10. | 1 | 4294967291 |
  11. | 1 | 4294967293 |
  12. | 1 | 4294967294 |
  13. | 1 | 4294967295 |
  14. +------+------------+
  15. 5 rows in set (0.01 sec)
  • BIGINT and BIGINT UNSIGNED
  1. -- Create a table named "inttable" with 2 attributes of a "bigint", a "bigint unsigned",
  2. drop table inttable;
  3. create table inttable ( a bigint, big bigint primary key );
  4. insert into inttable values (122345515, 0xFFFFFFFFFFFFE), (1234567, 0xFFFFFFFFFFFF0);
  5. mysql> select * from inttable;
  6. +-----------+------------------+
  7. | a | big |
  8. +-----------+------------------+
  9. | 122345515 | 4503599627370494 |
  10. | 1234567 | 4503599627370480 |
  11. +-----------+------------------+
  12. 2 rows in set (0.01 sec)

Real Numbers

Data TypeSizePrecisionMin ValueMax ValueSyntax
FLOAT324 bytes23 bits-3.40282e+0383.40282e+038FLOAT(M, D)
M represents the maximum length and D represents the number of decimal places displayed. The value range of M is (1=< M <=255).
The value range of D is (1=< D <=30), and M >= D.
Float numbers with precision show the number of bits with the required precision, and a trailing zero is added when the number of bits falls short.
FLOAT648 bytes53 bits-1.79769e+3081.79769e+308DOUBLE(M, D)
M represents the maximum length and D represents the number of decimal places displayed. The value range of M is (1=< M <=255).
The value range of D is (1=< D <=30), and M >= D.
Float numbers with precision show the number of bits with the required precision, and a trailing zero is added when the number of bits falls short.

Examples

  1. -- Create a table named "floatt1" with precision, a trailing zero is added when the number of bits falls short
  2. create table floatt1(a float(5, 2));
  3. insert into floatt1 values(1), (2.5), (3.56), (4.678);
  4. mysql> select * from floatt1;
  5. +------+
  6. | a |
  7. +------+
  8. | 1.00 |
  9. | 2.50 |
  10. | 3.56 |
  11. | 4.68 |
  12. +------+
  13. 4 rows in set (0.00 sec)
  14. -- Create a table named "floattable" with 1 attributes of a "float"
  15. create table floattable ( a float not null default 1, big float(20,5) primary key);
  16. insert into floattable (big) values (-1),(12345678.901234567),(92233720368547.75807);
  17. mysql> select * from floattable order by a desc, big asc;
  18. +------+----------------------+
  19. | a | big |
  20. +------+----------------------+
  21. | 1 | -1.00000 |
  22. | 1 | 12345679.00000 |
  23. | 1 | 92233718038528.00000 |
  24. +------+----------------------+
  25. 3 rows in set (0.01 sec)
  26. mysql> select min(big),max(big),max(big)-1 from floattable;
  27. +----------+----------------------+----------------+
  28. | min(big) | max(big) | max(big) - 1 |
  29. +----------+----------------------+----------------+
  30. | -1.00000 | 92233718038528.00000 | 92233718038527 |
  31. +----------+----------------------+----------------+
  32. 1 row in set (0.05 sec)

String Types

Data TypeSizeLengthSyntaxDescription
char24 bytes0 ~ 4294967295CHARFixed length string
varchar24 bytes0 ~ 4294967295VARCHARVariable length string
binary255 bytes0 ~ 65535BINARY(M)Similar to CHAR, binary string
varbinary255 bytes0 ~ 65535VARBINARY(M)Similar to VARCHAR, binary string
text1 GBother types mappingTEXTLong text data, TINY TEXT, MEDIUM TEXT, and LONG TEXT are not distinguished
blob1 GBother types mappingBLOBLong text data in binary form, TINY BLOB, MEDIUM BLOB, and LONG BLOB are not distinguished
enum1 byte or 2 bytes0 ~ 65535enumAn enumeration. A string object that can have only one value, chosen from the list of values ‘value1’, ‘value2’, …, NULL or the special ‘’ error value. ENUM values are represented internally as integers.

Examples

  • CHAR and VARCHAR
  1. -- Create a table named "names" with 2 attributes of a "varchar" and a "char"
  2. create table names(name varchar(255),age char(255));
  3. insert into names(name, age) values('Abby', '24');
  4. insert into names(name, age) values("Bob", '25');
  5. insert into names(name, age) values('Carol', "23");
  6. insert into names(name, age) values("Dora", "29");
  7. mysql> select name,age from names;
  8. +-------+------+
  9. | name | age |
  10. +-------+------+
  11. | Abby | 24 |
  12. | Bob | 25 |
  13. | Carol | 23 |
  14. | Dora | 29 |
  15. +-------+------+
  16. 4 rows in set (0.00 sec)
  • BINARY and VARBINARY
  1. -- Create a table named "names" with 2 attributes of a "varchar" and a "char"
  2. create table names(name varbinary(255),age binary(255));
  3. insert into names(name, age) values('Abby', '24');
  4. insert into names(name, age) values("Bob", '25');
  5. insert into names(name, age) values('Carol', "23");
  6. insert into names(name, age) values("Dora", "29");
  7. mysql> select name,age from names;
  8. +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  9. | name | age |
  10. +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  11. | 0x41626279 | 0x323400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
  12. | 0x426F62 | 0x323500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
  13. | 0x4361726F6C | 0x323300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
  14. | 0x446F7261 | 0x323900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
  15. +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. 4 rows in set (0.01 sec)
  • TEXT
  1. -- Create a table named "texttest" with 1 attribute of a "text"
  2. create table texttest (a text);
  3. insert into texttest values('abcdef');
  4. insert into texttest values('_bcdef');
  5. insert into texttest values('a_cdef');
  6. insert into texttest values('ab_def');
  7. insert into texttest values('abc_ef');
  8. insert into texttest values('abcd_f');
  9. insert into texttest values('abcde_');
  10. mysql> select * from texttest where a like 'ab\_def' order by 1 asc;
  11. +--------+
  12. | a |
  13. +--------+
  14. | ab_def |
  15. +--------+
  16. 1 row in set (0.01 sec)
  • BLOB
  1. -- Create a table named "blobtest" with 1 attribute of a "blob"
  2. create table blobtest (a blob);
  3. insert into blobtest values('abcdef');
  4. insert into blobtest values('_bcdef');
  5. insert into blobtest values('a_cdef');
  6. insert into blobtest values('ab_def');
  7. insert into blobtest values('abc_ef');
  8. insert into blobtest values('abcd_f');
  9. insert into blobtest values('abcde_');
  10. mysql> select * from blobtest where a like 'ab\_def' order by 1 asc;
  11. +----------------+
  12. | a |
  13. +----------------+
  14. | 0x61625F646566 |
  15. +----------------+
  16. 1 row in set (0.01 sec)
  • ENUM
  1. -- Create a table named "enumtest" with 1 attribute of a "enum"
  2. CREATE TABLE enumtest (color ENUM('red', 'green', 'blue'));
  3. INSERT INTO enumtest (color) VALUES ('red');
  4. mysql> SELECT * FROM enumtest WHERE color = 'green';
  5. +-------+
  6. | color |
  7. +-------+
  8. | green |
  9. +-------+
  10. 1 row in set (0.01 sec)

JSON Types

JSON Data TypeSyntax
ObjectObject is enclosed by {}, separated by commas between key-value pairs, and separated by colons : between keys and values.
The value/key can be String, Number, Bool, Time and date.
ArrayArray is enclosed by [], separated by commas between key-value pairs, and separated by colons : between keys and values.
The value can be String, Number, Bool, Time and date.

Examples

  1. -- Create a table named "jsontest" with 1 attribute of a "json"
  2. create table jsontest (a json,b int);
  3. insert into jsontest values ('{"t1":"a"}',1),('{"t1":"b"}',2);
  4. mysql> select * from jsontest;
  5. +-------------+------+
  6. | a | b |
  7. +-------------+------+
  8. | {"t1": "a"} | 1 |
  9. | {"t1": "b"} | 2 |
  10. +-------------+------+
  11. 2 rows in set (0.01 sec)

Time and Date Types

Data TypeSizeResolutionMin ValueMax ValuePrecision
Time8 bytesmicrosecond-2562047787:59:59.9999992562047787:59:59.999999hh:mm:ss.ssssss
Date4 bytesday0001-01-019999-12-31YYYY-MM-DD/YYYYMMDD
DateTime8 bytesmicrosecond0001-01-01 00:00:00.0000009999-12-31 23:59:59.999999YYYY-MM-DD hh:mi:ssssss
TIMESTAMP8 bytesmicrosecond0001-01-01 00:00:00.0000009999-12-31 23:59:59.999999YYYYMMDD hh:mi:ss.ssssss

Examples

  • TIME
  1. -- Create a table named "timetest" with 1 attributes of a "time"
  2. create table time_02(t1 time);
  3. insert into time_02 values(200);
  4. insert into time_02 values("");
  5. mysql> select * from time_02;
  6. +----------+
  7. | t1 |
  8. +----------+
  9. | 00:02:00 |
  10. | NULL |
  11. +----------+
  12. 2 rows in set (0.00 sec)
  • DATE
  1. -- Create a table named "datetest" with 1 attributes of a "date"
  2. create table datetest (a date not null, primary key(a));
  3. insert into datetest values ('2022-01-01'), ('20220102'),('2022-01-03'),('20220104');
  4. mysql> select * from datetest order by a asc;
  5. +------------+
  6. | a |
  7. +------------+
  8. | 2022-01-01 |
  9. | 2022-01-02 |
  10. | 2022-01-03 |
  11. | 2022-01-04 |
  12. +------------+
  • DATETIME
  1. -- Create a table named "datetimetest" with 1 attributes of a "datetime"
  2. create table datetimetest (a datetime(0) not null, primary key(a));
  3. insert into datetimetest values ('20200101000000'), ('2022-01-02'), ('2022-01-02 00:00:01'), ('2022-01-02 00:00:01.512345');
  4. mysql> select * from datetimetest order by a asc;
  5. +---------------------+
  6. | a |
  7. +---------------------+
  8. | 2020-01-01 00:00:00 |
  9. | 2022-01-02 00:00:00 |
  10. | 2022-01-02 00:00:01 |
  11. | 2022-01-02 00:00:02 |
  12. +---------------------+
  13. 4 rows in set (0.02 sec)
  • TIMESTAMP
  1. -- Create a table named "timestamptest" with 1 attribute of a "timestamp"
  2. create table timestamptest (a timestamp(0) not null, primary key(a));
  3. insert into timestamptest values ('20200101000000'), ('2022-01-02'), ('2022-01-02 00:00:01'), ('2022-01-02 00:00:01.512345');
  4. mysql> select * from timestamptest;
  5. +---------------------+
  6. | a |
  7. +---------------------+
  8. | 2020-01-01 00:00:00 |
  9. | 2022-01-02 00:00:00 |
  10. | 2022-01-02 00:00:01 |
  11. | 2022-01-02 00:00:02 |
  12. +---------------------+

Bool

Data TypeSize
True1 byte
False1 byte

Examples

  1. -- Create a table named "booltest" with 2 attribute of a "boolean" and b "bool"
  2. create table booltest (a boolean,b bool);
  3. insert into booltest values (0,1),(true,false),(true,1),(0,false),(NULL,NULL);
  4. mysql> select * from booltest;
  5. +-------+-------+
  6. | a | b |
  7. +-------+-------+
  8. | false | true |
  9. | true | false |
  10. | true | true |
  11. | false | false |
  12. | NULL | NULL |
  13. +-------+-------+
  14. 5 rows in set (0.00 sec)

Decimal Types

Data TypeSizePrecisionSyntax
Decimal648 bytes18 digitsDecimal(N,S)
N is the total number of digits, the range is(1 ~ 18). The decimal point and (for negative numbers) the - sign are not counted in N.
If N is omitted, the default value of N should be the largest; that is, the value is 18.
S is the number of digits after the decimal point (the scale), the range is(0 ~ N)
If S is 0, values have no decimal point or fractional part. If S is omitted, the default is 0, for example, Decimal(10) is equivalent to Decimal(10, 0).
For example, Decimal(10,8) represents a number with a total length of 10 and a decimal place of 8.
Decimal12816 bytes38 digitsDecimal(N,S)
N is the total number of digits, the range is(18 ~ 38). The decimal point and (for negative numbers) the - sign are not counted in N.
If N is omitted, the default value of N should be the largest; that is, the value is 38.
S is the number of digits after the decimal point (the scale), the range is(0 ~ N)
If S is 0, values have no decimal point or fractional part. If S is omitted, the default is 0, for example, Decimal(20) is equivalent to Decimal(20, 0).
For example, Decimal(20,9) represents a number with a total length of 20 and a decimal place of 9.

Examples

  1. -- Create a table named "decimalTest" with 2 attribute of a "decimal" and b "decimal"
  2. create table decimalTest(a decimal(6,3), b decimal(24,18));
  3. insert into decimalTest values(123.4567, 123456.1234567891411241355);
  4. mysql> select * from decimalTest;
  5. +---------+---------------------------+
  6. | a | b |
  7. +---------+---------------------------+
  8. | 123.457 | 123456.123456789141124136 |
  9. +---------+---------------------------+
  10. 1 row in set (0.01 sec)

UUID Type

UUID typeExplanation
UUIDA UUID value consists of 32 hexadecimal digits and 4 hyphens ‘-‘, in the form of 8-4-4-4-12, a standard UUID example: a0eebc99 -9c0b-4ef8-bb6d-6bb9bd380a11.

Example

  1. -- Create a new table named 't1' and set the 'a' column as UUID type, and set the 'a' column as the primary key
  2. create table t1(a uuid primary key);
  3. -- Insert a new UUID value into column 'a' of table 't1'
  4. insert into t1 values ​​(uuid());
  5. -- Query the length of the value of the 'a' column in the 't1' table converted to a string
  6. mysql> select length(cast(a as varchar)) from t1;
  7. +----------------------------+
  8. |length(cast(a as varchar))|
  9. +----------------------------+
  10. | 36 |
  11. +----------------------------+
  12. 1 row in set (0.01 sec)
  13. -- Query all records in the t1 table, whose value is a UUID
  14. mysql> select * from t1;
  15. +----------------------------------------+
  16. | a |
  17. +----------------------------------------+
  18. | 948d8e4e-1b00-11ee-b656-5ad2460dea50 |
  19. +----------------------------------------+
  20. 1 row in set (0.00 sec)