Selecting a proper data type for table fields improves database performance and storage efficiency, helps maintain database data integrity and readability, and enhances database security and consistency. This topic describes the data types supported by ApsaraDB for SelectDB. You can execute the SHOW DATA TYPES; statement to query the data types that are supported by SelectDB.
Numeric data types
Data type | Number of bytes | Description |
BOOLEAN | 1 | A Boolean value. Valid values: 0: false. 1: true. |
TINYINT | 1 | A signed integer. Valid values: -128 to 127. |
SMALLINT | 2 | A signed integer. Valid values: -32768 to 32767. |
INT | 4 | A signed integer. Valid values: -2147483648 to 2147483647. |
BIGINT | 8 | A signed integer. Valid values: -9223372036854775808 to 9223372036854775807. |
LARGEINT | 16 | A signed integer. Valid values: -2^127 + 1 to 2^127 - 1. |
FLOAT | 4 | A floating-point number. Valid values: -3.4 × 10^38 to 3.4 × 10^38. |
DOUBLE | 8 | A floating-point number. Valid values: -1.79 × 10^308 to 1.79 × 10^308. |
DECIMAL | 4/8/16 | A high-precision fixed-point number. Syntax:
|
Date and time data types
Data type | Number of bytes | Description |
DATE | 16 | A date. Valid values: '0000-01-01' to '9999-12-31'. Default output format: |
DATETIME | 16 | A date and time. Syntax: Note P:
Valid values: '0000-01-01 00:00:00[.000000]' to '9999-12-31 23:59:59[.999999]'. Default output format: |
String data types
Data type | Number of bytes | Description |
CHAR | M | A fixed-length string. Syntax: Note M indicates the number of bytes that a fixed-length string contains. Valid values of M: 1 to 255. |
VARCHAR | Indefinite | A variable-length string. Syntax: Note
Valid values of M: 1 to 65533. |
STRING | Indefinite | A variable-length string. Default and minimum length: 1,048,576 bytes, which is equal to 1 MB. Maximum length: 2,147,483,643 bytes, which is equal to 2 GB. Important
|
Semi-structured data types
Data type | Number of bytes | Description |
ARRAY | Indefinite | An array that consists of elements of Type T. Syntax: ARRAY<T>. Note
Usage notes:
|
MAP | Indefinite | A map that consists of key-value pairs. Syntax: MAP<K,V>. Note The following types are supported for the key-value pairs: Usage notes:
|
STRUCT | Indefinite | A structure composed of multiple fields. The structure is a collection of multiple columns. Syntax: STRUCT<field_name:field_type, ... > Note
Usage notes:
|
JSON | Indefinite | The JSON data type stores data in a binary format. Internal fields are accessed by using JSON functions. Default length: 1,048,576 bytes, which is equal to 1 MB. Maximum length: 2,147,483,643 bytes, which is equal to 2 GB. Note You can modify the |
VARIANT | Indefinite | The dynamic variable data type, which is developed for semi-structured data such as JSON data. This type of data can be stored in any JSON data field. The system automatically splits a JSON data field into sub-columns for storage. This improves the storage efficiency and query and analysis performance. The VARIANT data type is suitable for complex nested data structures, which can change at any time. Usage notes:
Important Make sure that your instance runs SelectDB Core |
Aggregation data types
Data type | Number of bytes | Description |
HLL | Indefinite | An approximate count of distinct elements. The performance of HyperLogLog (HLL) is higher than Count Distinct if the amount of data is large. Usage notes:
|
BITMAP | Indefinite | An exact count of distinct elements, which is applicable to scenarios such as unique visitor (UV) count or audience selection. Usage notes:
|
QUANTILE_STATE | Indefinite | The data type that can be used to calculate the approximate value of quantiles. Different values with the same key are pre-aggregated when data is imported.
Usage notes:
|
AGG_STATE | Indefinite | The aggregate function. It is used to accelerate aggregations and can be used only with the Usage notes:
|
IP address data types
The following data types are supported only for SelectDB Core 4.0.0 or later. If your instance runs a kernel version earlier than SelectDB Core 4.0.0, upgrade the kernel version. For more information, see Update the kernel version of an instance.
Data type | Number of bytes | Description |
IPv4 | 4 bytes | Stores an IPv4 address in a 4-byte binary string. The IPv4 address data type is used with ipv4_* functions. |
IPv6 | 16 bytes | Stores an IPv6 address in a 16-byte binary string. The IPv6 address data type is used with ipv6_* functions. |