Skip to content

Commit

Permalink
Add note about SELECT CAST(MeN AS CHAR) incompatibility (#13518) (#13558
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ti-chi-bot committed May 15, 2023
1 parent 0b38b49 commit ae9cc0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions data-type-numeric.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ DOUBLE PRECISION [(M,D)] [UNSIGNED] [ZEROFILL], REAL[(M,D)] [UNSIGNED] [ZEROFILL
>
> As in MySQL, the `DOUBLE` data type stores approximate values. For values such as currency, it is recommended to use the `DECIMAL` type instead.
> **Note:**
>
> When TiDB converts a double-precision floating-point number represented in scientific notation to the `CHAR` type, the result is displayed inconsistently with that in MySQL. See [Cast functions and operators](/functions-and-operators/cast-functions-and-operators.md) for details.
## Fixed-point types

TiDB supports all the MySQL floating-point types, including DECIMAL, and NUMERIC. For more information, [Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC in MySQL](https://dev.mysql.com/doc/refman/5.7/en/fixed-point-types.html).
Expand Down
8 changes: 6 additions & 2 deletions functions-and-operators/cast-functions-and-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ summary: Learn about the cast functions and operators.

# Cast Functions and Operators

TiDB supports all of the [cast functions and operators](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html) available in MySQL 5.7.
Cast functions and operators enable conversion of values from one data type to another. TiDB supports all of the [cast functions and operators](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html) available in MySQL 5.7.

## List of cast functions and operators

| Name | Description |
| ---------------------------------------- | -------------------------------- |
| [`BINARY`](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#operator_binary) | Cast a string to a binary string |
| [`CAST()`](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast) | Cast a value as a certain type |
| [`CONVERT()`](https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert) | Cast a value as a certain type |

Cast functions and operators enable conversion of values from one data type to another.
> **Note:**
>
> TiDB and MySQL display inconsistent results for `SELECT CAST(MeN AS CHAR)` (or its equivalent form `SELECT CONVERT(MeM, CHAR)`), where `MeN` represents a double-precision floating-point number in scientific notation. MySQL displays the complete numeric value when `-15 <= N <= 14` and the scientific notation when `N < -15` or `N > 14`. However, TiDB always displays the complete numeric value. For example, MySQL displays the result of `SELECT CAST(3.1415e15 AS CHAR)` as `3.1415e15`, while TiDB displays the result as `3141500000000000`.

0 comments on commit ae9cc0e

Please sign in to comment.