Skip to content

Commit

Permalink
Add note about SELECT CAST(MeN AS CHAR) incompatibility (#7663) (#13965)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored May 15, 2023
1 parent 3dccb7c commit 6a2d14b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions data-type-numeric.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ DOUBLE PRECISION [(M,D)] [UNSIGNED] [ZEROFILL], REAL[(M,D)] [UNSIGNED] [ZEROFILL
>
> 与在 MySQL 中一样,`DOUBLE` 数据类型存储近似值。对于货币之类的精确值,建议使用 `DECIMAL` 类型。
> **注意:**
>
> 当 TiDB 将用科学计数法表示的双精度浮点数转换到 `CHAR` 类型时,其结果在显示上与 MySQL 不一致,详情参见 [Cast 函数和操作符](/functions-and-operators/cast-functions-and-operators.md)
### 存储空间

每种类型对存储空间的需求如下表所示:
Expand Down
4 changes: 4 additions & 0 deletions functions-and-operators/cast-functions-and-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ Cast 函数和操作符用于将某种数据类型的值转换为另一种数据
| [`BINARY`](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#operator_binary) | 将一个字符串转换成一个二进制字符串 |
| [`CAST()`](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast) | 将一个值转换成一个确定类型 |
| [`CONVERT()`](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert) | 将一个值转换成一个确定类型 |

> **注意:**
>
> TiDB 和 MySQL 对于 `SELECT CAST(MeN AS CHAR)`(或者等价的 `SELECT CONVERT(MeM, CHAR)`)的结果显示不一致,其中 `MeN` 是用科学计数法表示的双精度浮点数。MySQL 在 `-15 <= N <= 14` 时显示完整数值,在 `N < -15``N > 14` 时显示科学计数法。而 TiDB 始终显示完整数值。例如,MySQL 对于 `SELECT CAST(3.1415e15 AS CHAR)` 的显示结果为 `3.1415e15`,而 TiDB 的显示结果为 `3141500000000000`

0 comments on commit 6a2d14b

Please sign in to comment.