Skip to content

Commit

Permalink
docs(DataTypes): update the docs of data types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nliver authored and mergify[bot] committed Jan 14, 2023
1 parent 11d8bdb commit 29e3f7c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
54 changes: 25 additions & 29 deletions Docs/05-SQL-reference/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ sidebar_position: 6.2
---

# Data Types

The following table lists the data types supported by StoneDB.

| **Category** | **Data type** |
Expand All @@ -16,45 +15,42 @@ The following table lists the data types supported by StoneDB.
| String | CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT |
| Binary string | BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB |

:::caution

When you create a StoneDB table, do not include keyword **unsigned** or **zerofill**.

:::


## Integer data types
# Integer data types
The following table provides the value range of each integer data type.

| **Data type** | **Bytes of storage** | **Min. value** | **Max. value** |
| --- | --- | --- | --- |
| TINYINT | 1 | -128 | 127 |
| SMALLINT | 2 | -32768 | 32767 |
| MEDIUMINT | 3 | -8388608 | 8388607 |
| INT | 4 | -2147483647 | 2147483647 |
| BIGINT | 8 | -9223372036854775808 | 9223372036854775807 |
| **Data type** | **Bytes of storage** | **Signed** | **Min. value** | **Max. value** |
| --- | --- | --- | --- | --- |
| TINYINT | 1 | Yes | -128 | 127 |
| | | No | 0 | 127 |
| SMALLINT | 2 | Yes | -32768 | 32767 |
| | | No | 0 | 32767 |
| MEDIUMINT | 3 | Yes | -8388608 | 8388607 |
| | | No | 0 | 8388607 |
| INT | 4 | Yes | -2147483647 | 2147483647 |
| | | unsigned | 0 | 2147483647 |
| BIGINT | 8 | Yes | -9223372036854775808 | 9223372036854775807 |
| | | unsigned | 0 | 18446744073709551615 |

On StoneDB, the precision for DECIMAL numbers cannot be higher than 18. For example, if you specify **decimal(19)** in your code, an error will be reported. **DECIMAL(6, 2)** indicates that up to 6 places are supported at the left of the decimal and up to 2 at the right, and thus the value range is [-9999.99, 9999.99].

## String data types
# String data types
The storage required for a string varies according to the character set in use. The length range also differs. The following table describes the length range of each string data type when character set latin1 is in use.

| **Data type** | **Size** |
| --- | --- |
| CHAR(M) | [0,255] |
| VARCHAR(M) | [0,65535] |
| TINYTEXT | [0,255] |
| TEXT | [0,65535] |
| MEDIUMTEXT | [0,16777215] |
| LONGTEXT | [0,4294967295] |

## Date and time data types
| CHAR(M) | [0, 255] |
| VARCHAR(M) | [0, 65535] |
| TINYTEXT | [0, 255] |
| TEXT | [0, 65535] |
| MEDIUMTEXT | [0, 16777215] |
| LONGTEXT | [0, 4294967295] |

# Date and time data types
The following table describes the value range of each date and time data type.

| **Data type** | **Format** | **Min. value** | **Max. value** |
| --- | --- | --- | --- |
| YEAR | YYYY | 1901 | 2155 |
| TIME | HH:MM:SS | -838:59:59 | 838:59:59 |
| DATE | YYYY-MM-DD | 0001-01-01 | 9999-12-31 |
| DATETIME | YYYY-MM-DD HH:MM:SS | 0001-01-01 00:00:00 | 9999-12-31 23:59:59 |
| TIMESTAMP | YYYY-MM-DD HH:MM:SS | 1970-01-01 08:00:01 | 2038-01-19 11:14:07 |
| DATE | YYYY-MM-DD | 0000-00-00 | 9999-12-31 |
| DATETIME | YYYY-MM-DD HH:MM:SS | 0000-00-00 00:00:00 | 9999-12-31 23:59:59 |
| TIMESTAMP | YYYY-MM-DD HH:MM:SS | 1970-01-01 08:00:01 | 2038-01-19 11:14:07 |
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ StoneDB 支持如下的数据类型。
| 字符串型 | CHAR、VARCHAR、TINYTEXT、TEXT、MEDIUMTEXT、LONGTEXT |
| 二进制字符串型 | BINARY、VARBINARY、TINYBLOB、BLOB、MEDIUMBLOB、LONGBLOB |

在 StoneDB 创建表时不支持使用关键字 unsigned、zerofill,各整型的取值范围如下。

| 类型 | 字节 | 最小值 | 最大值 |
| --- | --- | --- | --- |
| TINYINT | 1 | -128 | 127 |
| SMALLINT | 2 | -32768 | 32767 |
| MEDIUMINT | 3 | -8388608 | 8388607 |
| INT | 4 | -2147483647 | 2147483647 |
| BIGINT | 8 | -9223372036854775808 | 9223372036854775807 |

DECIMAL 精度必须小于或等于18,否则不支持,如 decimal(19) 就会报错。DECIMAL(6, 2) 表示整数部分和小数部分最大有效位数分别为4和2,所以值域为 [-9999.99, 9999.99]

不同的字符集,即使长度相同,但占用的存储空间不同,以下是以字符集为 latin1 的字符串类型的大小范围。
各整型的取值范围如下。

| 类型 | 字节 | 有/无符号 | 最小值 | 最大值 |
| --- | --- | --- | --- | --- |
| TINYINT | 1 | 有符号 | -128 | 127 |
| | | 无符号 | 0 | 127 |
| SMALLINT | 2 | 有符号 | -32768 | 32767 |
| | | 无符号 | 0 | 32767 |
| MEDIUMINT | 3 | 有符号 | -8388608 | 8388607 |
| | | 无符号 | 0 | 8388607 |
| INT | 4 | 有符号 | -2147483647 | 2147483647 |
| | | 无符号 | 0 | 2147483647 |
| BIGINT | 8 | 有符号 | -9223372036854775808 | 9223372036854775807 |
| | | 无符号 | 0 | 18446744073709551615 |

DECIMAL 精度必须小于或等于18,否则不支持,如 decimal(19) 就会报错。DECIMAL(6, 2) 表示整数部分和小数部分最大有效位数分别为4和2,所以值域为 [-9999.99, 9999.99]。<br />不同的字符集,即使长度相同,但占用的存储空间不同,以下是以字符集为 latin1 的字符串类型的大小范围。

| 类型 | 大小 |
| --- | --- |
Expand All @@ -45,6 +48,6 @@ DECIMAL 精度必须小于或等于18,否则不支持,如 decimal(19) 就会
| --- | --- | --- | --- |
| YEAR | YYYY | 1901 | 2155 |
| TIME | HH:MM:SS | -838:59:59 | 838:59:59 |
| DATE | YYYY-MM-DD | 0001-01-01 | 9999-12-31 |
| DATETIME | YYYY-MM-DD HH:MM:SS | 0001-01-01 00:00:00 | 9999-12-31 23:59:59 |
| TIMESTAMP | YYYY-MM-DD HH:MM:SS | 1970-01-01 08:00:01 | 2038-01-19 11:14:07 |
| DATE | YYYY-MM-DD | 0000-00-00 | 9999-12-31 |
| DATETIME | YYYY-MM-DD HH:MM:SS | 0000-00-00 00:00:00 | 9999-12-31 23:59:59 |
| TIMESTAMP | YYYY-MM-DD HH:MM:SS | 1970-01-01 08:00:01 | 2038-01-19 11:14:07 |

0 comments on commit 29e3f7c

Please sign in to comment.