Skip to content

Commit

Permalink
docs(Docs/website): update description on data type content stoneatom…
Browse files Browse the repository at this point in the history
  • Loading branch information
hustjieke committed Feb 28, 2023
1 parent f8df638 commit f306881
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
33 changes: 20 additions & 13 deletions Docs/05-SQL-reference/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,29 @@ The following table lists the data types supported by StoneDB.
| Binary string | BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB |

# Integer data types

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

| **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 |
| | | No | 0 | 2147483647 |
| BIGINT | 8 | Yes | -9223372036854775806 | 9223372036854775807 |
| | | No | 0 | 9223372036854775807 |
Type | Storage (Bytes) | Minimum Value Signed | Minimum Value Unsigned | Maximum Value Signed | Maximum Value Unsigned
-- | -- | -- | -- | -- | --
TINYINT | 1 | -128 | 0 | 127 | 255
SMALLINT | 2 | -32768 | 0 | 32767 | 65535
MEDIUMINT | 3 | -8388608 | 0 | 8388607 | 16777215
INT | 4 | -2147483647 | 0 | 2147483647 | 4294967295
BIGINT | 8 | -9223372036854775806 | 0 | 9223372036854775807 | 9223372036854775807

**Notice**:

For `INT` type: `-2147483648` is reserved to indicate `INT_NULL` in `Tianmu` engine, `Minimum Value Signed` start from -2147483647.

For `BIGINT` type: `-9223372036854775807` is reserved to indicate `BIGINT_NULL` in `Tianmu`, `Maximum Value Signed` start from -9223372036854775806.

For `BIGINT` type: Maximum Value Unsigned currently limited to 9223372036854775807, we'll expand it to 18446744073709551615 in the future.

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

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** |
Expand All @@ -46,6 +52,7 @@ The storage required for a string varies according to the character set in use.
| 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** |
Expand All @@ -54,4 +61,4 @@ The following table describes the value range of each date and time data type.
| TIME | HH:MM:SS | -838:59:59 | 838:59:59 |
| 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 |
| 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,22 +16,31 @@ StoneDB 支持如下的数据类型:
| 字符串型 | CHAR、VARCHAR、TINYTEXT、TEXT、MEDIUMTEXT、LONGTEXT |
| 二进制字符串型 | BINARY、VARBINARY、TINYBLOB、BLOB、MEDIUMBLOB、LONGBLOB |

# 整型数据类型

各整型的取值范围如下:

| 类型 | 字节 | 有/无符号 | 最小值 | 最大值 |
| --- | --- | --- | --- | --- |
| 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 | 有符号 | -9223372036854775806 | 9223372036854775807 |
| | | 无符号 | 0 | 9223372036854775807 |

DECIMAL 精度必须小于或等于18,否则不支持,如 decimal(19) 就会报错。DECIMAL(6, 2) 表示整数部分和小数部分最大有效位数分别为4和2,所以值域为 [-9999.99, 9999.99]。<br />不同的字符集,即使长度相同,但占用的存储空间不同,以下是以字符集为 latin1 的字符串类型的大小范围。
类型 | 存储(字节) | 有符号最小值 | 无符号最小值 | 有符号最大值 | 无符号最大值
-- | -- | -- | -- | -- | --
TINYINT | 1 | -128 | 0 | 127 | 255
SMALLINT | 2 | -32768 | 0 | 32767 | 65535
MEDIUMINT | 3 | -8388608 | 0 | 8388607 | 16777215
INT | 4 | -2147483647 | 0 | 2147483647 | 4294967295
BIGINT | 8 | -9223372036854775806 | 0 | 9223372036854775807 | 9223372036854775807

**注意**

`INT` 类型: `-2147483648``Tianmu` 引擎中预留给 `INT_NULL`,有符号最小值从 -2147483647 开始。

`BIGINT` 类型: `-9223372036854775807``Tianmu` 引擎中预留给 `BIGINT_NULL`,有符号最小值从 -9223372036854775806 开始。

`BIGINT` 类型: 无符号号最大值限制在 9223372036854775807, 未来我们会扩展到 18446744073709551615。

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

# 字符串类型

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

| 类型 | 大小 |
| --- | --- |
Expand All @@ -42,6 +51,8 @@ DECIMAL 精度必须小于或等于18,否则不支持,如 decimal(19) 就会
| MEDIUMTEXT | [0,16777215] |
| LONGTEXT | [0,4294967295] |

# 日期和时间类型

日期类型的日期范围如下:

| 类型 | 日期格式 | 最小值 | 最大值 |
Expand All @@ -50,4 +61,4 @@ DECIMAL 精度必须小于或等于18,否则不支持,如 decimal(19) 就会
| TIME | HH:MM:SS | -838:59:59 | 838:59:59 |
| 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 |
| TIMESTAMP | YYYY-MM-DD HH:MM:SS | 1970-01-01 08:00:01 | 2038-01-19 11:14:07 |

0 comments on commit f306881

Please sign in to comment.