From a1a3e07238542503e5724bf1c94fbca1b4d7268e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Tue, 26 Mar 2024 10:14:20 +0100 Subject: [PATCH 01/12] cast-functions-and-operators: Update reference manual links --- .../cast-functions-and-operators.md | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index 3eb512f074f69..2eb229dde6319 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -6,16 +6,67 @@ aliases: ['/docs/dev/functions-and-operators/cast-functions-and-operators/','/do # Cast Functions and Operators -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. +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/8.0/en/cast-functions.html) available in MySQL 8.0. ## List of cast functions and operators | Name | Description | | ---------------------------------------- | -------------------------------- | -| [`BINARY`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary) | Cast a string to a binary string | +| [`BINARY`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary) | Cast a string to a binary string. | | [`CAST()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast) | Cast a value as a certain type | | [`CONVERT()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_convert) | Cast a value as a certain type | > **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`. + +### BINARY + +The `BINARY` operator has been deprecated in MySQL 8.0.27. It is recommended to use `CAST(... AS BINARY)` instead both in TiDB and MySQL. + +### CAST + +The `CAST()` function cast an expression to a specific type. + +This function is also used to create [Multi-valued Indexes](/sql-statements/sql-statement-create-index.md#multi-valued-indexes). + +Example: + +```sql +SELECT CAST(0x54694442 AS CHAR); +``` + +``` ++--------------------------+ +| CAST(0x54694442 AS CHAR) | ++--------------------------+ +| TiDB | ++--------------------------+ +1 row in set (0.0002 sec) +``` + + +### CONVERT + +The `CONVERT()` function is used to convert between [character sets](/character-set-and-collation.md). + +Example + +```sql +SELECT CONVERT(0x616263 USING utf8mb4); +``` + +``` ++---------------------------------+ +| CONVERT(0x616263 USING utf8mb4) | ++---------------------------------+ +| abc | ++---------------------------------+ +1 row in set (0.0004 sec) +``` + +# MySQL Compatibility + +- TiDB doesn't support cast operations on spatial types. [GitHub Issue #6347](https://github.com/pingcap/tidb/issues/6347) +- TiDB doesn't support `AT TIME ZONE` for `CAST()`. [GitHub Issue #51742](https://github.com/pingcap/tidb/issues/51742) +- `CAST(24 AS YEAR)` returns 2 digits in TiDB and 4 digits in MySQL. [GitHub Issue 29629](https://github.com/pingcap/tidb/issues/29629) \ No newline at end of file From fc78ddd5b708238eb566d328854da7d793376a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Tue, 26 Mar 2024 16:22:58 +0100 Subject: [PATCH 02/12] Update functions-and-operators/cast-functions-and-operators.md --- functions-and-operators/cast-functions-and-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index 2eb229dde6319..c3241a644b1ed 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -12,7 +12,7 @@ Cast functions and operators enable conversion of values from one data type to a | Name | Description | | ---------------------------------------- | -------------------------------- | -| [`BINARY`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary) | Cast a string to a binary string. | +| [`BINARY`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary) | Cast a string to a binary string | | [`CAST()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast) | Cast a value as a certain type | | [`CONVERT()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_convert) | Cast a value as a certain type | From dfab54fc68b38aaada4d2ecd12d11355199f442b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Tue, 26 Mar 2024 16:27:45 +0100 Subject: [PATCH 03/12] Update functions-and-operators/cast-functions-and-operators.md --- functions-and-operators/cast-functions-and-operators.md | 1 - 1 file changed, 1 deletion(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index c3241a644b1ed..6b296606e433c 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -45,7 +45,6 @@ SELECT CAST(0x54694442 AS CHAR); 1 row in set (0.0002 sec) ``` - ### CONVERT The `CONVERT()` function is used to convert between [character sets](/character-set-and-collation.md). From 439759758ef53facd9a45e0c30e6ce5c18c1eae7 Mon Sep 17 00:00:00 2001 From: bb7133 Date: Tue, 16 Apr 2024 12:10:36 -0700 Subject: [PATCH 04/12] Update functions-and-operators/cast-functions-and-operators.md --- functions-and-operators/cast-functions-and-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index 6b296606e433c..539fc71b5201d 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -68,4 +68,4 @@ SELECT CONVERT(0x616263 USING utf8mb4); - TiDB doesn't support cast operations on spatial types. [GitHub Issue #6347](https://github.com/pingcap/tidb/issues/6347) - TiDB doesn't support `AT TIME ZONE` for `CAST()`. [GitHub Issue #51742](https://github.com/pingcap/tidb/issues/51742) -- `CAST(24 AS YEAR)` returns 2 digits in TiDB and 4 digits in MySQL. [GitHub Issue 29629](https://github.com/pingcap/tidb/issues/29629) \ No newline at end of file +- `CAST(24 AS YEAR)` returns 2 digits in TiDB and 4 digits in MySQL. [GitHub Issue #29629](https://github.com/pingcap/tidb/issues/29629) \ No newline at end of file From fa49e6cf6afbf590f1646ef8f4e05dbf93b4ca96 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Wed, 17 Apr 2024 14:35:18 +0800 Subject: [PATCH 05/12] adjust the sub section levels --- .../cast-functions-and-operators.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index 539fc71b5201d..3460b2cbe463c 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -8,23 +8,21 @@ aliases: ['/docs/dev/functions-and-operators/cast-functions-and-operators/','/do 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/8.0/en/cast-functions.html) available in MySQL 8.0. -## List of cast functions and operators - | Name | Description | | ---------------------------------------- | -------------------------------- | -| [`BINARY`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary) | Cast a string to a binary string | -| [`CAST()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast) | Cast a value as a certain type | -| [`CONVERT()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_convert) | Cast a value as a certain type | +| [`BINARY`](/binary) | Cast a string to a binary string | +| [`CAST()`](/cast) | Cast a value as a certain type | +| [`CONVERT()`](/convert) | Cast a value as a certain type | > **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`. -### BINARY +## BINARY The `BINARY` operator has been deprecated in MySQL 8.0.27. It is recommended to use `CAST(... AS BINARY)` instead both in TiDB and MySQL. -### CAST +## CAST The `CAST()` function cast an expression to a specific type. @@ -45,7 +43,7 @@ SELECT CAST(0x54694442 AS CHAR); 1 row in set (0.0002 sec) ``` -### CONVERT +## CONVERT The `CONVERT()` function is used to convert between [character sets](/character-set-and-collation.md). @@ -68,4 +66,4 @@ SELECT CONVERT(0x616263 USING utf8mb4); - TiDB doesn't support cast operations on spatial types. [GitHub Issue #6347](https://github.com/pingcap/tidb/issues/6347) - TiDB doesn't support `AT TIME ZONE` for `CAST()`. [GitHub Issue #51742](https://github.com/pingcap/tidb/issues/51742) -- `CAST(24 AS YEAR)` returns 2 digits in TiDB and 4 digits in MySQL. [GitHub Issue #29629](https://github.com/pingcap/tidb/issues/29629) \ No newline at end of file +- `CAST(24 AS YEAR)` returns 2 digits in TiDB and 4 digits in MySQL. [GitHub Issue #29629](https://github.com/pingcap/tidb/issues/29629) From b916ae3c5f1b3f35c7f137f834575819b192cec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Wed, 17 Apr 2024 08:52:41 +0200 Subject: [PATCH 06/12] Update functions-and-operators/cast-functions-and-operators.md Co-authored-by: Grace Cai --- functions-and-operators/cast-functions-and-operators.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index 3460b2cbe463c..e40a80c082828 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -62,8 +62,8 @@ SELECT CONVERT(0x616263 USING utf8mb4); 1 row in set (0.0004 sec) ``` -# MySQL Compatibility +# MySQL compatibility -- TiDB doesn't support cast operations on spatial types. [GitHub Issue #6347](https://github.com/pingcap/tidb/issues/6347) -- TiDB doesn't support `AT TIME ZONE` for `CAST()`. [GitHub Issue #51742](https://github.com/pingcap/tidb/issues/51742) -- `CAST(24 AS YEAR)` returns 2 digits in TiDB and 4 digits in MySQL. [GitHub Issue #29629](https://github.com/pingcap/tidb/issues/29629) +- TiDB does not support cast operations on spatial types. For more information, see [#6347](https://github.com/pingcap/tidb/issues/6347). +- TiDB does not support `AT TIME ZONE` for `CAST()`. For more information, see [#51742](https://github.com/pingcap/tidb/issues/51742). +- `CAST(24 AS YEAR)` returns 2 digits in TiDB and 4 digits in MySQL. For more information, see [#29629](https://github.com/pingcap/tidb/issues/29629). From 186ab08744515412914489681c04a907848476a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Wed, 17 Apr 2024 08:53:49 +0200 Subject: [PATCH 07/12] Apply suggestions from code review Co-authored-by: Grace Cai --- .../cast-functions-and-operators.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index e40a80c082828..30f89e0b521b2 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -20,13 +20,13 @@ Cast functions and operators enable conversion of values from one data type to a ## BINARY -The `BINARY` operator has been deprecated in MySQL 8.0.27. It is recommended to use `CAST(... AS BINARY)` instead both in TiDB and MySQL. +The [`BINARY`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary) operator has been deprecated since MySQL 8.0.27. It is recommended to use `CAST(... AS BINARY)` instead both in TiDB and MySQL. ## CAST -The `CAST()` function cast an expression to a specific type. +The [`CAST()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_cast) function is used to cast an expression to a specific type. -This function is also used to create [Multi-valued Indexes](/sql-statements/sql-statement-create-index.md#multi-valued-indexes). +This function is also used to create [Multi-valued indexes](/sql-statements/sql-statement-create-index.md#multi-valued-indexes). Example: @@ -45,9 +45,9 @@ SELECT CAST(0x54694442 AS CHAR); ## CONVERT -The `CONVERT()` function is used to convert between [character sets](/character-set-and-collation.md). +The [`CONVERT()`](https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#function_convert) function is used to convert between [character sets](/character-set-and-collation.md). -Example +Example: ```sql SELECT CONVERT(0x616263 USING utf8mb4); From 2c9e9679e9bf33ba202db6a6ceea9113dcb26898 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Wed, 17 Apr 2024 15:10:50 +0800 Subject: [PATCH 08/12] Update functions-and-operators/cast-functions-and-operators.md --- functions-and-operators/cast-functions-and-operators.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index 30f89e0b521b2..ce63c57c057a0 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -10,9 +10,9 @@ Cast functions and operators enable conversion of values from one data type to a | Name | Description | | ---------------------------------------- | -------------------------------- | -| [`BINARY`](/binary) | Cast a string to a binary string | -| [`CAST()`](/cast) | Cast a value as a certain type | -| [`CONVERT()`](/convert) | Cast a value as a certain type | +| [`BINARY`](#binary) | Cast a string to a binary string | +| [`CAST()`](#cast) | Cast a value as a certain type | +| [`CONVERT()`](#convert) | Cast a value as a certain type | > **Note:** > From 8eb38d07a16b1329056cc2493c7d5c2245f6cfd7 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Wed, 24 Apr 2024 17:29:46 +0800 Subject: [PATCH 09/12] format udpates --- functions-and-operators/cast-functions-and-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index ce63c57c057a0..139f1ae178fbb 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -62,7 +62,7 @@ SELECT CONVERT(0x616263 USING utf8mb4); 1 row in set (0.0004 sec) ``` -# MySQL compatibility +## MySQL compatibility - TiDB does not support cast operations on spatial types. For more information, see [#6347](https://github.com/pingcap/tidb/issues/6347). - TiDB does not support `AT TIME ZONE` for `CAST()`. For more information, see [#51742](https://github.com/pingcap/tidb/issues/51742). From 6db27732fe0afec387e3a1005a51c2e3215a6030 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Wed, 24 Apr 2024 17:43:54 +0800 Subject: [PATCH 10/12] format udpates --- functions-and-operators/cast-functions-and-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index 139f1ae178fbb..039ce8fe46063 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -64,6 +64,6 @@ SELECT CONVERT(0x616263 USING utf8mb4); ## MySQL compatibility -- TiDB does not support cast operations on spatial types. For more information, see [#6347](https://github.com/pingcap/tidb/issues/6347). +- TiDB does not support cast operations on `SPATIAL` types. For more information, see [#6347](https://github.com/pingcap/tidb/issues/6347). - TiDB does not support `AT TIME ZONE` for `CAST()`. For more information, see [#51742](https://github.com/pingcap/tidb/issues/51742). - `CAST(24 AS YEAR)` returns 2 digits in TiDB and 4 digits in MySQL. For more information, see [#29629](https://github.com/pingcap/tidb/issues/29629). From 4f51dfa9be13cc74a0ef6e72abf6bb0367199e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Thu, 25 Apr 2024 12:40:05 +0200 Subject: [PATCH 11/12] Update functions-and-operators/cast-functions-and-operators.md Co-authored-by: xixirangrang --- functions-and-operators/cast-functions-and-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index 039ce8fe46063..bf38ba04f74b7 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -34,7 +34,7 @@ Example: SELECT CAST(0x54694442 AS CHAR); ``` -``` +```sql +--------------------------+ | CAST(0x54694442 AS CHAR) | +--------------------------+ From cb6a6d8c9ea3643edf56df2d3d720a4a98dc16c2 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Fri, 26 Apr 2024 15:39:43 +0800 Subject: [PATCH 12/12] Update functions-and-operators/cast-functions-and-operators.md --- functions-and-operators/cast-functions-and-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/cast-functions-and-operators.md b/functions-and-operators/cast-functions-and-operators.md index bf38ba04f74b7..9ac5cab6eb9d0 100644 --- a/functions-and-operators/cast-functions-and-operators.md +++ b/functions-and-operators/cast-functions-and-operators.md @@ -53,7 +53,7 @@ Example: SELECT CONVERT(0x616263 USING utf8mb4); ``` -``` +```sql +---------------------------------+ | CONVERT(0x616263 USING utf8mb4) | +---------------------------------+