This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new 4b260e92596 [cast](numbers) add cast docs for casting to numbers
(#2649)
4b260e92596 is described below
commit 4b260e92596038d89ddba6af216a7499085e0d09
Author: TengJianPing <[email protected]>
AuthorDate: Tue Jul 22 17:34:38 2025 +0800
[cast](numbers) add cast docs for casting to numbers (#2649)
## Versions
- [x] dev
- [ ] 3.0
- [ ] 2.1
- [ ] 2.0
## Languages
- [x] Chinese
- [x] English
## Docs Checklist
- [x] Checked by AI
- [ ] Test Cases Built
---
.../conversion/decimal-conversion.md | 274 ++++++++++++++++
.../conversion/float-double-conversion.md | 352 +++++++++++++++++++++
.../sql-data-types/conversion/int-conversion.md | 334 +++++++++++++++++++
.../conversion/decimal-conversion.md | 274 ++++++++++++++++
.../conversion/float-double-conversion.md | 352 +++++++++++++++++++++
.../sql-data-types/conversion/int-conversion.md | 334 +++++++++++++++++++
sidebars.json | 3 +
7 files changed, 1923 insertions(+)
diff --git
a/docs/sql-manual/basic-element/sql-data-types/conversion/decimal-conversion.md
b/docs/sql-manual/basic-element/sql-data-types/conversion/decimal-conversion.md
new file mode 100644
index 00000000000..f0ad257f663
--- /dev/null
+++
b/docs/sql-manual/basic-element/sql-data-types/conversion/decimal-conversion.md
@@ -0,0 +1,274 @@
+---
+{
+ "title": "Cast to DECIMAL",
+ "language": "en"
+}
+---
+
+## From string
+
+### Strict mode
+
+If the source type is nullable, returns nullable type;
+
+If the source type is non-nullable, returns non-nullable type;
+
+#### BNF definition
+
+```xml
+<decimal> ::= <whitespace>* <value> <whitespace>*
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+
+<value> ::= <sign>? <significand> <exponent>?
+
+<sign> ::= "+" | "-"
+
+<significand> ::= <digits> "." <digits> | <digits> | <digits> "." | "."
<digits>
+
+<digits> ::= <digit>+
+
+<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<exponent> ::= <e_marker> <sign>? <digits>
+
+<e_marker> ::= "e" | "E"
+```
+
+#### Rule description
+
+* Only supports decimal digits;
+
+* Supports scientific notation;
+
+* Supports rounding;
+
+* Strings allow arbitrary prefix and suffix whitespace characters, including:
" ", "\t", "\n", "\r", "\f", "\v".
+
+* Return error when integer part overflows;
+
+* Return error for invalid format.
+
+#### Examples
+
+| String | Decimal(18, 6) | Comment
|
+| --------------------------------- | -------------- |
---------------------------------------- |
+| "123.1234567" | 123.123457 | Rounding
|
+| "12345." | 12345.000000 |
|
+| "12345" | 12345.000000 |
|
+| ".123456" | 0.123456 |
|
+| " \t\r\n\f\v123.456 \t\r\n\f\v" | 123.456000 | With prefix and suffix
whitespace |
+| " \t\r\n\f\v+123.456 \t\r\n\f\v" | 123.456000 | With prefix and suffix
whitespace, positive sign |
+| " \t\r\n\f\v-123.456 \t\r\n\f\v" | -123.456000 | With prefix and suffix
whitespace, negative sign |
+| " \t\r\n\f\v+1.234e5 \t\r\n\f\v" | 123400.000000 | Scientific notation
|
+| " \t\r\n\f\v+1.234e+5 \t\r\n\f\v" | 123400.000000 | Scientific notation
with positive exponent |
+| " \t\r\n\f\v+1.234e-1 \t\r\n\f\v" | 0.123400 | Scientific notation
with negative exponent |
+| "123.456a" | Error | Invalid format
|
+| "1234567890123.123456" | Error | Overflow
|
+
+### Non-strict mode
+
+Always returns nullable type;
+
+#### BNF definition
+
+```xml
+<decimal> ::= <whitespace>* <value> <whitespace>*
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+
+<value> ::= <sign>? <significand> <exponent>
+
+<sign> ::= "+" | "-"
+
+<significand> ::= <digits> | <digits> "." <digits> | <digits> "." | "."
<digits>
+
+<digits> ::= <digit>+
+
+<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<exponent> ::= <e_marker> <sign>? <digits>
+
+<e_marker> ::= "e" | "E"
+```
+
+#### Rule description
+
+* Supports all valid formats from strict mode;
+
+* Converts to NULL when overflow occurs;
+
+* Converts to NULL for invalid format.
+
+#### Examples
+
+| String | Decimal(18, 6) | Comment
|
+| --------------------------------- | -------------- |
---------------------------------------- |
+| "123.1234567" | 123.123457 | Rounding
|
+| "12345." | 12345.000000 |
|
+| "12345" | 12345.000000 |
|
+| ".123456" | 0.123456 |
|
+| " \t\r\n\f\v123.456 \t\r\n\f\v" | 123.456000 | With prefix and suffix
whitespace |
+| " \t\r\n\f\v+123.456 \t\r\n\f\v" | 123.456000 | With prefix and suffix
whitespace, positive sign |
+| " \t\r\n\f\v-123.456 \t\r\n\f\v" | -123.456000 | With prefix and suffix
whitespace, negative sign |
+| " \t\r\n\f\v+1.234e5 \t\r\n\f\v" | 123400.000000 | Scientific notation
|
+| " \t\r\n\f\v+1.234e+5 \t\r\n\f\v" | 123400.000000 | Scientific notation
with positive exponent |
+| " \t\r\n\f\v+1.234e-1 \t\r\n\f\v" | 0.123400 | Scientific notation
with negative exponent |
+| "123.456a" | NULL | Invalid format
|
+| "1234567890123.123456" | NULL | Overflow
|
+
+## From bool
+
+true converts to 1, false converts to 0.
+
+### Strict mode
+
+Error when overflow occurs (e.g., `cast bool as decimal(1, 1)`).
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+### Non-strict mode
+
+Converts to NULL when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable:
+
+* If overflow is possible (e.g., `cast bool as decimal(1, 1)`), returns
nullable type;
+
+* Otherwise returns non-nullable type.
+
+## From integer
+
+### Strict mode
+
+Error when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| int | Decimal(18, 9) | Comment |
+| ---------- | -------------- | ------- |
+| 123 | 123.00000000 | |
+| 2147483647 | Error | Overflow |
+
+### Non-strict mode
+
+Converts to NULL when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable:
+
+* If overflow is possible (e.g., `cast int as decimal(1, 0)`), returns
nullable type;
+
+* Otherwise returns non-nullable type (e.g., `cast int as decimal(18, 0)`).
+
+#### Examples
+
+| int | Decimal(18, 9) | Comment |
+| ---------- | -------------- | ------- |
+| 123 | 123.00000000 | |
+| 2147483647 | NULL | Overflow |
+
+## From float/double
+
+Supports rounding.
+
+### Strict mode
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+* Infinity and NaN cause errors.
+
+* Error when overflow occurs.
+
+#### Examples
+
+| float/double | Decimal(18, 3) | Comment |
+| ------------ | -------------- | ------- |
+| 1.1239 | 1.124 | Rounding |
+| 3.40282e+38 | Error | Overflow |
+| Infinity | Error | |
+| NaN | Error | |
+
+### Non-strict mode
+
+Always returns nullable type.
+
+* +/-Inf converts to NULL;
+
+* NaN converts to NULL;
+
+* Converts to NULL when overflow occurs.
+
+#### Examples
+
+| float/double | Decimal(18, 6) | Comment |
+| ------------ | -------------- | ------- |
+| 1.123456 | 1.123456 | |
+| 3.40282e+38 | NULL | Overflow |
+| Infinity | NULL | |
+| NaN | NULL | |
+
+## Cast between decimals
+
+Supports rounding.
+
+### Strict mode
+
+Error when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| Decimal(18, 8) | Decimal(10, 6) | Comment |
+| -------------- | -------------- | ------- |
+| 1234.12345678 | 1234.123457 | Rounding |
+| 12345.12345678 | Error | Integer part overflow |
+
+### Non-strict mode
+
+Converts to NULL when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable:
+
+* If overflow is possible (e.g., `cast decimal(18, 0) as decimal(9, 0)`),
returns nullable type;
+
+* Otherwise returns non-nullable type (e.g., `cast decimal(9, 0) as
decimal(18, 0)`).
+
+#### Examples
+
+| Decimal(18, 8) | Decimal(10, 6) | Comment |
+| -------------- | -------------- | ------- |
+| 1234.12345678 | 1234.123457 | Rounding |
+| 12345.12345678 | NULL | Integer part overflow |
+
+## From date
+
+Not supported.
+
+## From datetime
+
+Not supported.
+
+## From time
+
+Not supported.
+
+## From other types
+
+Not supported
\ No newline at end of file
diff --git
a/docs/sql-manual/basic-element/sql-data-types/conversion/float-double-conversion.md
b/docs/sql-manual/basic-element/sql-data-types/conversion/float-double-conversion.md
new file mode 100644
index 00000000000..0ffe8fbc7fa
--- /dev/null
+++
b/docs/sql-manual/basic-element/sql-data-types/conversion/float-double-conversion.md
@@ -0,0 +1,352 @@
+---
+{
+ "title": "Convert to float/double",
+ "language": "en"
+}
+---
+
+## From string
+
+:::caution Behavior Change
+Since version 4.0, the result of overflow is no longer NULL, but +/-Infinity.
+:::
+
+### Strict mode
+
+If the source type is nullable, returns nullable type;
+
+If the source type is non-nullable, returns non-nullable type;
+
+#### BNF definition
+
+```xml
+<float> ::= <whitespace>* <value> <whitespace>*
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+
+<value> ::= <decimal> | <infinity> | <nan>
+
+<decimal> ::= <sign>? <significand> <exponent>?
+
+<infinity> ::= <sign>? <inf_literal>
+
+<nan> ::= <sign>? <nan_literal>
+
+<sign> ::= "+" | "-"
+
+<significand> ::= <digits> | <digits> "." <digits> | <digits> "." | "."
<digits>
+
+<digits> ::= <digit>+
+
+<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<exponent> ::= <e_marker> <sign>? <digits>
+
+<e_marker> ::= "e" | "E"
+
+<inf_literal> ::= <"INF" case-insensitive> | <"INFINITY" case-insensitive>
+
+<nan_literal> ::= <"NAN" case-insensitive>
+```
+
+#### Rule description
+
+* Only supports decimal format numbers;
+
+* Supports scientific notation;
+
+* Numbers can be prefixed with positive or negative sign characters;
+
+* Strings allow arbitrary prefix and suffix whitespace characters, including:
" ", "\t", "\n", "\r", "\f", "\v";
+
+* Supports Infinity and NaN;
+
+* Return error for other formats;
+
+* Overflow converts to +|-Infinity.
+
+#### Examples
+
+| String | float/double | Comment
|
+| ----------------------------------- | ------------ |
---------------------------------------- |
+| "123.456" | 123.456 |
|
+| "123456." | 123456 |
|
+| "123456" | 123456 |
|
+| ".123456" | 0.123456 |
|
+| " \t\r\n\f\v123.456 \t\r\n\f\v" | 123.456 | With prefix and suffix
whitespace |
+| " \t\r\n\f\v+123.456 \t\r\n\f\v" | 123.456 | With prefix and suffix
whitespace, positive sign |
+| " \t\r\n\f\v-123.456 \t\r\n\f\v" | -123.456 | With prefix and suffix
whitespace, negative sign |
+| " \t\r\n\f\v+1.234e5 \t\r\n\f\v" | 123400 | Scientific notation
|
+| " \t\r\n\f\v+1.234e+5 \t\r\n\f\v" | 123400 | Scientific notation
with positive exponent |
+| " \t\r\n\f\v+1.23456e-1 \t\r\n\f\v" | 0.123456 | Scientific notation
with negative exponent |
+| "Infinity" | Infinity |
|
+| "NaN" | NaN |
|
+| "123.456a" | Error | Invalid format
|
+| "1.7e409" | Infinity | Overflow
|
+| "-1.7e409" | -Infinity | Overflow
|
+
+### Non-strict mode
+
+Always returns nullable type.
+
+#### BNF definition
+
+```xml
+<float> ::= <whitespace>* <value> <whitespace>*
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+
+<value> ::= <decimal> | <infinity> | <nan>
+
+<decimal> ::= <sign>? <significand> <exponent>?
+
+<infinity> ::= <sign>? <inf_literal>
+
+<nan> ::= <sign>? <nan_literal>
+
+<sign> ::= "+" | "-"
+
+<significand> ::= <digits> | <digits> "." <digits> | <digits> "." | "."
<digits>
+
+<digits> ::= <digit>+
+
+<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<exponent> ::= <e_marker> <sign>? <digits>
+
+<e_marker> ::= "e" | "E"
+
+<inf_literal> ::= <"INF" case-insensitive> | <"INFINITY" case-insensitive>
+
+<nan_literal> ::= <"NAN" case-insensitive>
+```
+
+#### Rule description
+
+* Supports all valid formats from strict mode;
+
+* Invalid format converts to NULL;
+
+* Overflow converts to +|-Infinity.
+
+#### Examples
+
+| String | float/double | Comment
|
+| ----------------------------------- | ------------ |
---------------------------------------- |
+| "123.456" | 123.456 |
|
+| "12345." | 12345 |
|
+| ".123456" | 0.123456 |
|
+| " \t\r\n\f\v123.456 \t\r\n\f\v" | 123.456 | With prefix and suffix
whitespace |
+| " \t\r\n\f\v+123.456 \t\r\n\f\v" | 123.456 | With prefix and suffix
whitespace, positive sign |
+| " \t\r\n\f\v-123.456 \t\r\n\f\v" | -123.456 | With prefix and suffix
whitespace, negative sign |
+| " \t\r\n\f\v+1.234e5 \t\r\n\f\v" | 123400 | Scientific notation
|
+| "Infinity" | Infinity |
|
+| "NaN" | NaN |
|
+| "123.456a" | NULL | Invalid format
|
+| "1.7e409" | Infinity | Overflow
|
+| "-1.7e409" | -Infinity | Overflow
|
+
+## From bool
+
+true converts to 1, false converts to 0.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+## From integer
+
+Follows C++ static cast semantics. May lose precision.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+## From float to double
+
+Follows C++ static cast semantics.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+## From double to float
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+### Rule description
+
+* Follows C++ static cast semantics.
+
+* Overflow converts to +-Infinity.
+
+### Examples
+
+| double | float | Comment |
+| ------------- | --------- | ------- |
+| 1.79769e+308 | Infinity | Overflow |
+| -1.79769e+308 | -Infinity | Overflow |
+
+## From decimal to float
+
+Casting Decimal type to float may lose precision.
+
+Doris's `Decimal(p, s)` type is actually represented by an integer in memory,
where the integer value equals `Decimal actual value * 10^s`. For example, a
`Decimal(10, 6)` value `1234.56789` is represented by integer value
`1234567890` in memory.
+
+When converting Decimal type to float or double type, Doris actually performs
the following operation: `static_cast<float>(integer value in memory) /
(10^scale)`.
+
+### Strict mode
+
+Converts to Infinity if overflow.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| Decimal(76, 6)
| float | Comment |
+|
----------------------------------------------------------------------------- |
--------- | ------------------------------------ |
+| 123456789.012345
| 123456790 | Casting to float will lose precision |
+|
9999999999999999999999999999999999999999999999999999999999999999999999.123456 |
Infinity | Overflow |
+
+### Non-strict mode
+
+Converts to Infinity if overflow.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| Decimal(76, 6)
| float | Comment |
+|
----------------------------------------------------------------------------- |
--------- | ------------------------------------ |
+| 123456789.012345
| 123456790 | Casting to float will lose precision |
+|
9999999999999999999999999999999999999999999999999999999999999999999999.123456 |
Infinity | Overflow |
+
+## From decimal to double
+
+Currently, Decimal type can have at most 76 significant digits. Casting to
double type does not have overflow issues, only precision loss issues.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+### Examples
+
+| Decimal(76, 6)
| double | Comment
|
+|
----------------------------------------------------------------------------- |
------------------ |
------------------------------------------------------------ |
+| 123456789.012345
| 123456789.012345 | 15 significant digits, casting to double will not lose
precision |
+| 12345678901.012345
| 12345678901.012344 | 17 significant digits, casting to double will lose
precision |
+|
9999999999999999999999999999999999999999999999999999999999999999999999.123456 |
1e+70 | Will lose precision
|
+
+## From date to float
+
+### Strict mode
+
+Return error.
+
+### Non-strict mode
+
+Concatenates the year, month, and day numbers of the date in order to form an
integer, with month and day treated as two digits, padding with a leading 0 if
less than 10. Then static_cast this integer to float, which may lose precision.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| date | float | Comment |
+| ---------- | -------- | -------------- |
+| 2025-04-21 | 20250420 | Precision loss |
+
+## From date to double
+
+### Strict mode
+
+Return error.
+
+### Non-strict mode
+
+Concatenates the year, month, and day numbers of the date in order to form an
integer, with month and day treated as two digits, padding with a leading 0 if
less than 10. Then static_cast this integer to double.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| date | double | Comment |
+| ---------- | -------- | ------------------------------------- |
+| 2025-04-21 | 20250421 | 8 significant digits, no precision loss |
+
+## From datetime to float
+
+### Strict mode
+
+Return error.
+
+### Non-strict mode
+
+Discards the microsecond part of datetime, then concatenates the year, month,
day, hour, minute, and second in order to form an integer, with month, day,
hour, minute, and second treated as two digits, padding with a leading 0 if
less than 10. Then static_cast this integer to float, which may lose precision.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| datetime | float | Comment |
+| -------------------------- | -------------- | -------------- |
+| 2025-03-14 17:00:01.123456 | 20250314170001 | Precision loss |
+| 9999-12-31 23:59:59.999999 | 99991231235959 | Precision loss |
+
+## From datetime to double
+
+### Strict mode
+
+Return error.
+
+### Non-strict mode
+
+Discards the microsecond part of datetime, then concatenates the year, month,
day, hour, minute, and second in order to form an integer, with month, day,
hour, minute, and second treated as two digits, padding with a leading 0 if
less than 10. Then static_cast this integer to double.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| datetime | double | Comment
|
+| -------------------------- | --------------- |
----------------------------------------------- |
+| 2025-03-14 17:00:01.123456 | 20250314170001 | 14 significant digits, no
precision loss |
+| 9999-12-31 23:59:59.999999 | 99991231235959 |
|
+
+## From time
+
+### Strict mode
+
+Return error.
+
+### Non-strict mode
+
+Converts to float/double number in microseconds.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| Time | float | Comment |
+| ---------------- | ------------- | ------- |
+| 00:00:01 | 1000000 | |
+| 838:59:58 | 3020398000000 | |
+| 838:59:58.123456 | 3020398123456 | |
+
+## From other types
+
+Not supported.
\ No newline at end of file
diff --git
a/docs/sql-manual/basic-element/sql-data-types/conversion/int-conversion.md
b/docs/sql-manual/basic-element/sql-data-types/conversion/int-conversion.md
new file mode 100644
index 00000000000..75a57f3e37d
--- /dev/null
+++ b/docs/sql-manual/basic-element/sql-data-types/conversion/int-conversion.md
@@ -0,0 +1,334 @@
+---
+{
+ "title": "Cast to int",
+ "language": "en"
+}
+---
+
+## From string
+
+### Strict mode
+
+If the source type is nullable, returns nullable type;
+
+If the source type is non-nullable, returns non-nullable type;
+
+#### BNF definition
+
+```xml
+<integer> ::= <whitespace>* <sign>? <decimal_digit>+ <whitespace>*
+
+<sign> ::= "+" | "-"
+
+<decimal_digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+```
+
+#### Rule description
+
+* Only supports decimal format numbers;
+
+* Numbers can be prefixed with positive or negative sign characters;
+
+* Strings allow arbitrary prefix and suffix whitespace characters, including:
' ', '\t', '\n', '\r', '\f', '\v';
+
+* Does not support scientific notation;
+
+* Return error for other formats;
+
+* Return error if overflow.
+
+#### Examples
+
+| String | Cast as int result | Comment
|
+| ----------------------------------- | ------------------ |
---------------------------------------- |
+| "2147483647" | 2147483647 |
|
+| "-2147483648" | -2147483648 |
|
+| " \t\r\n\f\v2147483647 \t\r\n\f\v" | 2147483647 | With prefix and
suffix whitespace |
+| " \t\r\n\f\v+2147483647 \t\r\n\f\v" | 2147483647 | With prefix and
suffix whitespace, positive sign |
+| " \t\r\n\f\v-2147483648 \t\r\n\f\v" | -2147483648 | With prefix and
suffix whitespace, negative sign |
+| 'abc' | Error | Invalid format
|
+| '123.456' | Error | Decimal format
not supported |
+| '1.23456e5' | Error | Scientific
notation not supported |
+| '2147483648' | Error | Overflow
|
+| '-2147483649' | Error | Overflow
|
+
+### Non-strict mode
+
+Always returns nullable type.
+
+#### BNF definition
+
+```xml
+<integer_non_strict> ::= <whitespace_char>* <sign>? <number> <whitespace_char>*
+
+<sign> ::= "+" | "-"
+
+<number> ::= <decimal_number> | <decimal_number> "."
<decimal_number> | <decimal_number> "." | "." <decimal_number>
+
+<decimal_number> ::= <decimal_digit>+
+
+<decimal_digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" |
"9"
+
+<whitespace_char> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+```
+
+#### Rule description
+
+* Supports all valid formats from strict mode;
+
+* Supports strict mode format followed by decimal part, conversion result
directly discards the decimal part;
+
+* Scientific notation format converts to NULL;
+
+* All other format cases convert to NULL;
+
+* Converts to NULL when overflow occurs.
+
+#### Examples
+
+| String | Cast as int result | Comment
|
+| ----------------------------------- | ------------------ |
---------------------------------------- |
+| "2147483647" | 2147483647 |
|
+| "-2147483648" | -2147483648 |
|
+| " \t\r\n\f\v2147483647 \t\r\n\f\v" | 2147483647 | With prefix and
suffix whitespace |
+| " \t\r\n\f\v+2147483647 \t\r\n\f\v" | 2147483647 | With prefix and
suffix whitespace, positive sign |
+| " \t\r\n\f\v-2147483648 \t\r\n\f\v" | -2147483648 | With prefix and
suffix whitespace, negative sign |
+| '123.456' | 123 |
|
+| '1.23456e5' | NULL | Scientific
notation |
+| 'abc' | NULL | Invalid format
|
+| '2147483648' | NULL | Overflow
|
+| '-2147483649' | NULL | Overflow
|
+
+## From bool
+
+true converts to 1, false converts to 0.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+## From integer to integer
+
+Supports conversion between any integer types.
+
+### Strict mode
+
+Return error when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| Bigint | int | Comment |
+| ----------- | ---------- | ------- |
+| 2147483647 | 2147483647 | |
+| 2147483648 | Error | Overflow |
+| -2147483649 | Error | Overflow |
+
+### Non-strict mode
+
+:::caution Behavior Change
+Since version 4.0, the result of overflow is no longer undefined value, but
NULL.
+:::
+
+Returns NULL when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable:
+
+* If overflow is possible (e.g., `cast bigint as int`), returns nullable type;
+
+* Otherwise returns non-nullable type (e.g., `cast int as bigint`).
+
+#### Examples
+
+| Bigint | int | Comment |
+| ----------- | ---------- | ------- |
+| 2147483647 | 2147483647 | |
+| 2147483648 | NULL | Overflow |
+| -2147483649 | NULL | Overflow |
+
+## From date
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+### Rule description
+
+:::caution Behavior Change
+Since version 4.0, does not support casting date to tinyint and smallint
anymore.
+:::
+
+* Does not support casting to tinyint and smallint, as overflow will
definitely occur.
+
+* Supports casting to int, bigint and largeint. Concatenates the year, month,
and day numbers of the date in order to form an integer, with month and day
treated as two digits, padding with a leading 0 if less than 10.
+
+### Examples
+
+| date | int |
+| ---------- | -------- |
+| 2025-03-14 | 20250314 |
+
+## From datetime
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+### Rule description
+
+:::caution Behavior Change
+Since version 4.0, does not support casting datetime to tinyint, smallint and
int anymore.
+:::
+
+* Does not support casting to tinyint, smallint, int, as overflow will
definitely occur;
+
+* Supports casting to bigint, largeint. Discards the microsecond part of
datetime, then concatenates year, month, day, hour, minute, second in order to
form an integer, with month, day, hour, minute, second treated as two digits,
padding with a leading 0 if less than 10.
+
+### Examples
+
+| datetime | int |
+| -------------------------- | -------------- |
+| 2025-03-14 17:00:01.123456 | 20250314170001 |
+| 9999-12-31 23:59:59.999999 | 99991231235959 |
+
+## From float/double
+
+Does not support rounding.
+
+### Strict mode
+
+#### Rule description
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+* Return error when overflow occurs;
+
+* Return error for Infinity and NaN values.
+
+#### Examples
+
+| float/double | Cast as int | Comment |
+| ------------ | ----------- | ------- |
+| 1.5 | 1 | Truncation |
+| 1.79769E308 | Error | Overflow |
+| Infinity | Error | |
+| NaN | Error | |
+
+### Non-strict mode
+
+Always returns nullable type.
+
+#### Rule description
+
+:::caution Behavior Change
+Since version 4.0, the result of overflow is no longer undefined value, but
NULL.
+:::
+
+* Converts to NULL when overflow occurs;
+
+* Infinity converts to NULL;
+
+* NaN converts to NULL.
+
+#### Examples
+
+| float/double | Cast as int | Comment |
+| ------------ | ----------- | ------- |
+| 1.5 | 1 | Truncation |
+| 1.79769E308 | NULL | Overflow |
+| Infinity | NULL | |
+| -Infinity | NULL | |
+| NaN | NULL | |
+
+## From decimal
+
+Does not support rounding.
+
+### Strict mode
+
+Return error when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| Decimal(18, 6) | int | comment |
+| --------------- | ----- | ---------- |
+| 1.654321 | 1 | Truncation |
+| 12345678901.123 | Error | Overflow |
+
+### Non-strict mode
+
+Converts to NULL when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable:
+
+* If overflow is possible (e.g., `cast decimal(18, 0) as int`), returns
nullable type;
+
+* Otherwise returns non-nullable type (e.g., `cast decimal(9, 0) as bigint`).
+
+#### Examples
+
+| Decimal(18, 6) | int | comment |
+| --------------- | ---- | ---------- |
+| 1.654321 | 1 | Truncation |
+| 12345678901.123 | NULL | Overflow |
+
+## From time
+
+Converts to microseconds.
+
+### Strict mode
+
+Return error when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable, returns non-nullable type.
+
+#### Examples
+
+| Time | int | Comment |
+| --------- | ------- | ------- |
+| 00:00:01 | 1000000 | |
+| 838:59:58 | Error | Overflow |
+
+### Non-strict mode
+
+:::caution Behavior Change
+Since version 4.0, the result of overflow is no longer undefined value, but
NULL.
+:::
+
+Converts to NULL when overflow occurs.
+
+If the source type is nullable, returns nullable type.
+
+If the source type is non-nullable:
+
+* If overflow is possible (e.g., `cast time as tinyint`), returns nullable
type;
+
+* Otherwise returns non-nullable type (e.g., `cast time as bigint`).
+
+#### Examples
+
+| Time | int | Comment |
+| --------- | ------- | ------- |
+| 00:00:01 | 1000000 | |
+| 838:59:58 | NULL | Overflow |
+
+## Other types
+
+Not supported
\ No newline at end of file
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/decimal-conversion.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/decimal-conversion.md
new file mode 100644
index 00000000000..42f542cbc93
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/decimal-conversion.md
@@ -0,0 +1,274 @@
+---
+{
+ "title": "转换为 DECIMAL",
+ "language": "zh-CN"
+}
+---
+
+## From string
+
+### 严格模式
+
+如果源类型是nullable,返回nullable类型;
+
+如果源类型是非nullable,返回非nullable类型;
+
+#### BNF定义
+
+```xml
+<decimal> ::= <whitespace>* <value> <whitespace>*
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+
+<value> ::= <sign>? <significand> <exponent>?
+
+<sign> ::= "+" | "-"
+
+<significand> ::= <digits> "." <digits> | <digits> | <digits> "." | "."
<digits>
+
+<digits> ::= <digit>+
+
+<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<exponent> ::= <e_marker> <sign>? <digits>
+
+<e_marker> ::= "e" | "E"
+```
+
+#### 规则描述
+
+* 只支持十进制数字;
+
+* 支持科学计数法;
+
+* 支持四舍五入;
+
+* 字符串允许有任意数量的前缀空格和后缀空格,空格字符包括:" ", "\t", "\n", "\r", "\f", "\v"。
+
+* 整数部分溢出时报错;
+
+* 非法格式报错。
+
+#### 例子
+
+| 字符串 | Decimal(18, 6) | comment |
+| --------------------------------- | -------------- | --------------- |
+| "123.1234567" | 123.123457 | 四舍五入 |
+| "12345." | 12345.000000 | |
+| "12345" | 12345.000000 | |
+| ".123456" | 0.123456 | |
+| " \t\r\n\f\v123.456 \t\r\n\f\v" | 123.456000 | 带前缀和后缀空白字符 |
+| " \t\r\n\f\v+123.456 \t\r\n\f\v" | 123.456000 | 带前缀和后缀空白字符,带正号。 |
+| " \t\r\n\f\v-123.456 \t\r\n\f\v" | -123.456000 | 带前缀和后缀空白字符,带负号。 |
+| " \t\r\n\f\v+1.234e5 \t\r\n\f\v" | 123400.000000 | 科学计数法。 |
+| " \t\r\n\f\v+1.234e+5 \t\r\n\f\v" | 123400.000000 | 科学计数法,指数带正号。 |
+| " \t\r\n\f\v+1.234e-1 \t\r\n\f\v" | 0.123400 | 科学计数法,指数带负号。 |
+| "123.456a" | 报错 | 非法格式。 |
+| "1234567890123.123456" | 报错 | 溢出 |
+
+### 非严格模式
+
+始终返回nullable类型;
+
+#### BNF定义
+
+```xml
+<decimal> ::= <whitespace>* <value> <whitespace>*
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+
+<value> ::= <sign>? <significand> <exponent>
+
+<sign> ::= "+" | "-"
+
+<significand> ::= <digits> | <digits> "." <digits> | <digits> "." | "."
<digits>
+
+<digits> ::= <digit>+
+
+<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<exponent> ::= <e_marker> <sign>? <digits>
+
+<e_marker> ::= "e" | "E"
+```
+
+#### 规则描述
+
+* 支持严格模式下的所有合法格式;
+
+* 溢出时转成NULL值;
+
+* 非法格式转成NULL值。
+
+#### 例子
+
+| 字符串 | Decimal(18, 6) | comment |
+| --------------------------------- | -------------- | --------------- |
+| "123.1234567" | 123.123457 | 四舍五入 |
+| "12345." | 12345.000000 | |
+| "12345" | 12345.000000 | |
+| ".123456" | 0.123456 | |
+| " \t\r\n\f\v123.456 \t\r\n\f\v" | 123.456000 | 带前缀和后缀空白字符 |
+| " \t\r\n\f\v+123.456 \t\r\n\f\v" | 123.456000 | 带前缀和后缀空白字符,带正号。 |
+| " \t\r\n\f\v-123.456 \t\r\n\f\v" | -123.456000 | 带前缀和后缀空白字符,带负号。 |
+| " \t\r\n\f\v+1.234e5 \t\r\n\f\v" | 123400.000000 | 科学计数法。 |
+| " \t\r\n\f\v+1.234e+5 \t\r\n\f\v" | 123400.000000 | 科学计数法,指数带正号。 |
+| " \t\r\n\f\v+1.234e-1 \t\r\n\f\v" | 0.123400 | 科学计数法,指数带负号。 |
+| "123.456a" | NULL | 非法格式。 |
+| "1234567890123.123456" | NULL | 溢出 |
+
+## From bool
+
+true转成1,false转成0。
+
+### 严格模式
+
+溢出时报错(比如`cast bool as decimal(1, 1)`)。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+### 非严格模式
+
+溢出时转成NULL。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable:
+
+* 如果可能溢出(比如`cast bool as decimal(1, 1)`),返回nullable类型;
+
+* 否则返回非nullable类型。
+
+## From integer
+
+### 严格模式
+
+溢出时报错。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| int | Decimal(18, 9) | Comment |
+| ---------- | -------------- | ------- |
+| 123 | 123.00000000 | |
+| 2147483647 | 报错 | 溢出 |
+
+### 非严格模式
+
+溢出时转成NULL值。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable:
+
+* 如果可能溢出(比如`cast int as decimal(1, 0)`),返回nullable类型;
+
+* 否则返回非nullable类型(比如`cast int as decimal(18, 0)`)。
+
+#### 例子
+
+| int | Decimal(18, 9) | Comment |
+| ---------- | -------------- | ------- |
+| 123 | 123.00000000 | |
+| 2147483647 | NULL | 溢出 |
+
+## From float/double
+
+支持四舍五入。
+
+### 严格模式
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+* Infinity和NaN报错。
+
+* 溢出时报错。
+
+#### 例子
+
+| float/double | Decimal(18, 3) | Comment |
+| ------------ | -------------- | ------- |
+| 1.1239 | 1.124 | 四舍五入 |
+| 3.40282e+38 | 报错 | 溢出 |
+| Infinity | 报错 | |
+| NaN | 报错 | |
+
+### 非严格模式
+
+始终返回nullable类型。
+
+* +/-Inf转成NULL;
+
+* NaN转成NULL;
+
+* 溢出时转成NULL。
+
+#### 例子
+
+| float/double | Decimal(18, 6) | Comment |
+| ------------ | ------------------- | ------- |
+| 1.123456 | 1.123456 | |
+| 3.40282e+38 | NULL | 溢出 |
+| Infinity | NULL | |
+| NaN | NULL | |
+
+## Cast between decimals
+
+支持四舍五入。
+
+### 严格模式
+
+溢出报错。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| Decimal(18, 8) | Decimal(10, 6) | Comment |
+| -------------- | -------------- | ------- |
+| 1234.12345678 | 1234.123457 | 四舍五入 |
+| 12345.12345678 | 报错 | 整数部分溢出 |
+
+### 非严格模式
+
+溢出转成NULL值。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable:
+
+* 如果可能溢出(比如`cast decimal(18, 0) as decimal(9, 0)`),返回nullable类型;
+
+* 否则返回非nullable类型(比如`cast decimal(9, 0) as decimal(18, 0)`)。
+
+#### 例子
+
+| Decimal(18, 8) | Decimal(10, 6) | Comment |
+| -------------- | -------------- | ------- |
+| 1234.12345678 | 1234.123457 | 四舍五入 |
+| 12345.12345678 | NULL | 整数部分溢出 |
+
+## From date
+
+不支持。
+
+## From datetime
+
+不支持。
+
+## From time
+
+不支持。
+
+## From其它类型
+
+不支持
\ No newline at end of file
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/float-double-conversion.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/float-double-conversion.md
new file mode 100644
index 00000000000..13019c59679
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/float-double-conversion.md
@@ -0,0 +1,352 @@
+---
+{
+ "title": "转换为 float/double",
+ "language": "zh-CN"
+}
+---
+
+## From string
+
+:::caution 行为变更
+自 4.0 起,溢出时结果不再是NULL,而是+/-Infinity。
+:::
+
+### 严格模式
+
+如果源类型是nullable,返回nullable类型;
+
+如果源类型是非nullable,返回非nullable类型;
+
+#### BNF定义
+
+```xml
+<float> ::= <whitespace>* <value> <whitespace>*
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+
+<value> ::= <decimal> | <infinity> | <nan>
+
+<decimal> ::= <sign>? <significand> <exponent>?
+
+<infinity> ::= <sign>? <inf_literal>
+
+<nan> ::= <sign>? <nan_literal>
+
+<sign> ::= "+" | "-"
+
+<significand> ::= <digits> | <digits> "." <digits> | <digits> "." | "."
<digits>
+
+<digits> ::= <digit>+
+
+<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<exponent> ::= <e_marker> <sign>? <digits>
+
+<e_marker> ::= "e" | "E"
+
+<inf_literal> ::= <"INF" case-insensitive> | <"INFINITY" case-insensitive>
+
+<nan_literal> ::= <"NAN" case-insensitive>
+```
+
+#### 规则描述
+
+* 只支持十进制格式的数字;
+
+* 支持科学计数法;
+
+* 数字前面可以带有正负符号字符;
+
+* 字符串允许有任意数量的前缀空格和后缀空格,空格字符包括:" ", "\t", "\n", "\r", "\f", "\v";
+
+* 支持Infinity和NaN;
+
+* 其它格式报错;
+
+* 溢出转成+|-Infinity。
+
+#### 例子
+
+| 字符串 | float/double | comment |
+| ----------------------------------- | ------------ | --------------- |
+| "123.456" | 123.456 | |
+| "123456." | 123456 | |
+| "123456" | 123456 | |
+| ".123456" | 0.123456 | |
+| " \t\r\n\f\v123.456 \t\r\n\f\v" | 123.456 | 带前缀和后缀空白字符 |
+| " \t\r\n\f\v+123.456 \t\r\n\f\v" | 123.456 | 带前缀和后缀空白字符,带正号。 |
+| " \t\r\n\f\v-123.456 \t\r\n\f\v" | -123.456 | 带前缀和后缀空白字符,带负号。 |
+| " \t\r\n\f\v+1.234e5 \t\r\n\f\v" | 123400 | 科学计数法。 |
+| " \t\r\n\f\v+1.234e+5 \t\r\n\f\v" | 123400 | 科学计数法,指数带正号。 |
+| " \t\r\n\f\v+1.23456e-1 \t\r\n\f\v" | 0.123456 | 科学计数法,指数是负数。 |
+| "Infinity" | Infinity | |
+| "NaN" | NaN | |
+| "123.456a" | 报错 | 非法格式。 |
+| "1.7e409" | Infinity | 溢出 |
+| "-1.7e409" | -Infinity | 溢出 |
+
+### 非严格模式
+
+始终返回nullable类型。
+
+#### BNF定义
+
+```xml
+<float> ::= <whitespace>* <value> <whitespace>*
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+
+<value> ::= <decimal> | <infinity> | <nan>
+
+<decimal> ::= <sign>? <significand> <exponent>?
+
+<infinity> ::= <sign>? <inf_literal>
+
+<nan> ::= <sign>? <nan_literal>
+
+<sign> ::= "+" | "-"
+
+<significand> ::= <digits> | <digits> "." <digits> | <digits> "." | "."
<digits>
+
+<digits> ::= <digit>+
+
+<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<exponent> ::= <e_marker> <sign>? <digits>
+
+<e_marker> ::= "e" | "E"
+
+<inf_literal> ::= <"INF" case-insensitive> | <"INFINITY" case-insensitive>
+
+<nan_literal> ::= <"NAN" case-insensitive>
+```
+
+#### 规则描述
+
+* 支持严格模式下的所有合法格式;
+
+* 非法格式转成NULL值;
+
+* 溢出转成+|-Infinity。
+
+#### 例子
+
+| 字符串 | float/double | comment |
+| -------------------------------- | ------------ | --------------- |
+| "123.456" | 123.456 | |
+| "12345." | 12345 | |
+| ".123456" | 0.123456 | |
+| " \t\r\n\f\v123.456 \t\r\n\f\v" | 123.456 | 带前缀和后缀空白字符 |
+| " \t\r\n\f\v+123.456 \t\r\n\f\v" | 123.456 | 带前缀和后缀空白字符,带正号。 |
+| " \t\r\n\f\v-123.456 \t\r\n\f\v" | -123.456 | 带前缀和后缀空白字符,带负号。 |
+| " \t\r\n\f\v+1.234e5 \t\r\n\f\v" | 123400 | 科学计数法。 |
+| "Infinity" | Infinity | |
+| "NaN" | NaN | |
+| "123.456a" | NULL | 非法格式。 |
+| "1.7e409" | Infinity | 溢出 |
+| "-1.7e409" | -Infinity | 溢出 |
+
+## From bool
+
+true转成1,false转成0。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+## From integer
+
+遵守c++ static cast语义。可能会丢失精度。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+## From float to double
+
+遵守c++ static cast语义。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+## From double to float
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+### 规则描述
+
+* 遵守c++ static cast语义。
+
+* 溢出时转成+-Infinity。
+
+### 例子
+
+| double | float | Comment |
+| ------------- | --------- | ------- |
+| 1.79769e+308 | Infinity | 溢出 |
+| -1.79769e+308 | -Infinity | 溢出 |
+
+## From decimal to float
+
+Decimal类型cast成float有可能会丢失精度。
+
+Doris的`Decimal(p, s)`类型,在内存中实际是用整数表示的,整数的值等于`Decimal实际值 *
10^s`。例如,一个`Decimal(10, 6)`的值`1234.56789`,在内存中是用整数值`1234567890`表示的。
+
+将Decimal类型转为float或者double类型时,Doris实际是执行以下操作:`static_cast<float>(内存中的整数值) / (10
^scale)`。
+
+### 严格模式
+
+溢出时转成Infinity。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| Decimal(76, 6)
| float | Comment |
+|
----------------------------------------------------------------------------- |
--------- | --------------- |
+| 123456789.012345
| 123456790 | cast成float会丢失精度 |
+|
9999999999999999999999999999999999999999999999999999999999999999999999.123456 |
Infinity | 溢出 |
+
+### 非严格模式
+
+溢出时转成Infinity。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| Decimal(76, 6)
| float | Comment |
+|
----------------------------------------------------------------------------- |
--------- | ---------------- |
+| 123456789.012345
| 123456790 | cast成float会丢失精度。 |
+|
9999999999999999999999999999999999999999999999999999999999999999999999.123456 |
Infinity | 溢出 |
+
+## From decimal to double
+
+目前Decimal类型有效数字最多是76位,cast成double类型不存在溢出问题,只会存在丢失精度问题。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+### 例子
+
+| Decimal(76, 6)
| double | Comment |
+|
----------------------------------------------------------------------------- |
------------------ | --------------------------- |
+| 123456789.012345
| 123456789.012345 | 有效位数是15位,cast成double不会丢失精度。 |
+| 12345678901.012345
| 12345678901.012344 | 有效位数是17位,cast成double会丢失精度。 |
+|
9999999999999999999999999999999999999999999999999999999999999999999999.123456 |
1e+70 | 会丢失精度。 |
+
+## From date to float
+
+### 严格模式
+
+报错。
+
+### 非严格模式
+
+将date的年月日的数字按顺序拼成整数,月、日都当成两位数,不足10的在前面补一个0。然后将这个整数static\_cast成float,可能会丢失精度。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| date | float | Comment |
+| ---------- | -------- | ------- |
+| 2025-04-21 | 20250420 | 丢失精度 |
+
+## From date to double
+
+### 严格模式
+
+报错。
+
+### 非严格模式
+
+将date的年月日的数字按顺序拼成整数,月、日都当成两位数,不足10的在前面补一个0。然后将这个整数static\_cast成double。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| date | double | Comment |
+| ---------- | -------- | ------------- |
+| 2025-04-21 | 20250421 | 8位有效数字,不会丢失精度 |
+
+## From datetime to float
+
+### 严格模式
+
+报错。
+
+### 非严格模式
+
+将datetime的microsend部分丢弃,然后将年、月、日、小时、分钟、秒按顺序拼接成一个整数,月、日、小时、分钟、秒都当成两位数,不足10的在前面补一个0。然后将这个整数static\_cast成float,会丢失精度。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| datetime | float | Comment |
+| -------------------------- | -------------- | ------- |
+| 2025-03-14 17:00:01.123456 | 20250314000000 | 丢失精度 |
+| 9999-12-31 23:59:59.999999 | 99991234000000 | 丢失精度 |
+
+## From datetime to double
+
+### 严格模式
+
+报错。
+
+### 非严格模式
+
+将datetime的microsend部分丢弃,然后将年、月、日、小时、分钟、秒按顺序拼接成一个整数,月、日、小时、分钟、秒都当成两位数,不足10的在前面补一个0。然后将这个整数static\_cast成double。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| datetime | double | Comment |
+| -------------------------- | --------------- | -------------- |
+| 2025-03-14 17:00:01.123456 | 20250314170001 | 14位有效数字,不会丢失精度 |
+| 9999-12-31 23:59:59.999999 | 99991231235959 | |
+
+## From time
+
+### 严格模式
+
+报错
+
+### 非严格模式
+
+转换成以微秒为单位的float/double数字。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| Time | float | Comment |
+| ---------------- | ------------- | ------- |
+| 00:00:01 | 1000000 | |
+| 838:59:58 | 3020398000000 | |
+| 838:59:58.123456 | 3020398123456 | |
+
+## From其它类型
+
+不支持
\ No newline at end of file
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/int-conversion.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/int-conversion.md
new file mode 100644
index 00000000000..9abd10cf43b
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/int-conversion.md
@@ -0,0 +1,334 @@
+---
+{
+ "title": "转换为 int",
+ "language": "zh-CN"
+}
+---
+
+## From string
+
+### 严格模式
+
+如果源类型是nullable,返回nullable类型;
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### BNF定义
+
+```xml
+<integer> ::= <whitespace>* <sign>? <decimal_digit>+ <whitespace>*
+
+<sign> ::= "+" | "-"
+
+<decimal_digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+```
+
+#### 规则描述
+
+* 只支持十进制格式的数字;
+
+* 数字前面可以带有正负符号字符;
+
+* 字符串允许有任意数量的前缀空格和后缀空格,空格字符包括:' ', '\t', '\n', '\r', '\f', '\v';
+
+* 不支持科学计数法;
+
+* 其它格式报错;
+
+* 数值溢出报错。
+
+#### 例子
+
+| 字符串 | Cast as int 结果 | Comment |
+| ----------------------------------- | -------------- | --------------- |
+| "2147483647" | 2147483647 | |
+| "-2147483648" | -2147483648 | |
+| " \t\r\n\f\v2147483647 \t\r\n\f\v" | 2147483647 | 带前缀和后缀空白字符 |
+| " \t\r\n\f\v+2147483647 \t\r\n\f\v" | 2147483647 | 带前缀和后缀空白字符,带正号。 |
+| " \t\r\n\f\v-2147483648 \t\r\n\f\v" | -2147483648 | 带前缀和后缀空白字符,带负号。 |
+| 'abc' | 报错 | 非法格式 |
+| '123.456' | 报错 | 不支持小数格式 |
+| '1.23456e5' | 报错 | 不支持科学计数法 |
+| '2147483648' | 报错 | 溢出 |
+| '-2147483649' | 报错 | 溢出 |
+
+### 非严格模式
+
+始终返回nullable类型。
+
+#### BNF定义
+
+```xml
+<integer_non_strict> ::= <whitespace_char>* <sign>? <number> <whitespace_char>*
+
+<sign> ::= "+" | "-"
+
+<number> ::= <decimal_number> | <decimal_number> "."
<decimal_number> | <decimal_number> "." | "." <decimal_number>
+
+<decimal_number> ::= <decimal_digit>+
+
+<decimal_digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" |
"9"
+
+<whitespace_char> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+```
+
+#### 规则描述
+
+* 支持严格模式下的所有合法格式;
+
+* 支持严格模式格式后面带有小数部分,转换结果直接把小数部分丢弃;
+
+* 科学计数法格式转成NULL;
+
+* 其他格式情况都转成NULL;
+
+* 溢出的时候转成NULL。
+
+#### 例子
+
+| 字符串 | Cast as int 结果 | Comment |
+| ----------------------------------- | -------------- | --------------- |
+| "2147483647" | 2147483647 | |
+| "-2147483648" | -2147483648 | |
+| " \t\r\n\f\v2147483647 \t\r\n\f\v" | 2147483647 | 带前缀和后缀空白字符 |
+| " \t\r\n\f\v+2147483647 \t\r\n\f\v" | 2147483647 | 带前缀和后缀空白字符,带正号。 |
+| " \t\r\n\f\v-2147483648 \t\r\n\f\v" | -2147483648 | 带前缀和后缀空白字符,带负号。 |
+| '123.456' | 123 | |
+| '1.23456e5' | NULL | 科学计数法 |
+| 'abc' | NULL | 非法格式 |
+| '2147483648' | NULL | 溢出 |
+| '-2147483649' | NULL | 溢出 |
+
+## From bool
+
+true转成1,false转成0。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+## From integer to integer
+
+支持任意整数类型之间相互转换。
+
+### 严格模式
+
+溢出时报错。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| Bigint | int | Comment |
+| ----------- | ---------- | ------- |
+| 2147483647 | 2147483647 | |
+| 2147483648 | 报错 | 溢出 |
+| -2147483649 | 报错 | 溢出 |
+
+### 非严格模式
+
+:::caution 行为变更
+自 4.0 起,溢出时结果不再是未定义值,而是NULL。
+:::
+
+溢出时返回NULL值。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable:
+
+* 如果可能溢出(比如`cast bigint as int`),返回nullable类型;
+
+* 否则返回非nullable类型(比如`cast int as bigint`)。
+
+#### 例子
+
+| Bigint | int | Comment |
+| ----------- | ---------- | ------- |
+| 2147483647 | 2147483647 | |
+| 2147483648 | NULL | 溢出 |
+| -2147483649 | NULL | 溢出 |
+
+## From date
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+### 规则描述
+
+:::caution 行为变更
+自 4.0 起,不再支持date类型转换成tinyint和smallint。
+:::
+
+* 不支持cast到tinyint和smallint,因为一定会溢出。
+
+* 支持cast成int, bigint和largeint。将date的年月日的数字按顺序拼成整数,月、日都当成两位数,不足10的在前面补一个0。
+
+### 例子
+
+| date | int |
+| ---------- | -------- |
+| 2025-03-14 | 20250314 |
+
+## From datetime
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+### 规则描述
+
+:::caution 行为变更
+自 4.0 起,不再支持datetime类型转换成tinyint、smallint和int类型。
+:::
+
+* 不支持cast到tinyint, smallint, int,因为一定会溢出;
+
+* 支持cast成bigint,
largeint。将datetime的microsend部分丢弃,然后将年、月、日、小时、分钟、秒按顺序拼接成一个整数,月、日、小时、分钟、秒都当成两位数,不足10的在前面补一个0。
+
+### 例子
+
+| datetime | int |
+| -------------------------- | -------------- |
+| 2025-03-14 17:00:01.123456 | 20250314170001 |
+| 9999-12-31 23:59:59.999999 | 99991231235959 |
+
+## From float/double
+
+不支持四舍五入。
+
+### 严格模式
+
+#### 规则描述
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+* 溢出时报错;
+
+* Inf和NaN值报错。
+
+#### 例子
+
+| float/double | Cast as int | Comment |
+| ------------ | ----------- | ------- |
+| 1.5 | 1 | 截断 |
+| 1.79769E308 | 报错 | 溢出 |
+| Infinity | 报错 | |
+| NaN | 报错 | |
+
+### 非严格模式
+
+始终返回nullable类型。
+
+#### 规则描述
+
+:::caution 行为变更
+自 4.0 起,溢出时结果不再是未定义值,而是NULL。
+:::
+
+* 溢出时转成NULL值;
+
+* Inf转成NULL值;
+
+* NaN转成NULL值。
+
+#### 例子
+
+| float/double | Cast as int | Comment |
+| ------------ | ----------- | ------- |
+| 1.5 | 1 | 截断 |
+| 1.79769E308 | NULL | 溢出 |
+| Infinity | NULL | |
+| -Infinity | NULL | |
+| NaN | NULL | |
+
+## From decimal
+
+不支持四舍五入。
+
+### 严格模式
+
+溢出时报错。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| Decimal(18, 6) | int | comment |
+| --------------- | --- | ------- |
+| 1.654321 | 1 | 截断 |
+| 12345678901.123 | 报错 | 溢出 |
+
+### 非严格模式
+
+溢出时转成NULL值。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable:
+
+* 如果可能溢出(比如`cast decimal(18, 0) as int`),返回nullable类型;
+
+* 否则返回非nullable类型(比如`cast decimal(9, 0) as bigint`)。
+
+#### 例子
+
+| Decimal(18, 6) | int | comment |
+| --------------- | ---- | ------- |
+| 1.654321 | 1 | 截断 |
+| 12345678901.123 | NULL | 溢出 |
+
+## From time
+
+转换为微秒数。
+
+### 严格模式
+
+溢出时报错。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable,返回非nullable类型。
+
+#### 例子
+
+| Time | int | Comment |
+| --------- | ------- | ------- |
+| 00:00:01 | 1000000 | |
+| 838:59:58 | 报错 | 溢出 |
+
+### 非严格模式
+
+:::caution 行为变更
+自 4.0 起,溢出时结果不再是未定义值,而是NULL。
+:::
+
+溢出时转成NULL值。
+
+如果源类型是nullable,返回nullable类型。
+
+如果源类型是非nullable:
+
+* 如果可能溢出(比如`cast time as tinyint`),返回nullable类型;
+
+* 否则返回非nullable类型(比如`cast time as bigint`)。
+
+#### 例子
+
+| Time | int | Comment |
+| --------- | ------- | ------- |
+| 00:00:01 | 1000000 | |
+| 838:59:58 | NULL | 溢出 |
+
+## 其它类型
+
+不支持
\ No newline at end of file
diff --git a/sidebars.json b/sidebars.json
index d172cda51e8..38a4df7d1f1 100644
--- a/sidebars.json
+++ b/sidebars.json
@@ -1028,6 +1028,9 @@
"sql-manual/basic-element/sql-data-types/conversion/boolean-conversion",
"sql-manual/basic-element/sql-data-types/conversion/date-conversion",
"sql-manual/basic-element/sql-data-types/conversion/datetime-conversion",
+
"sql-manual/basic-element/sql-data-types/conversion/decimal-conversion",
+
"sql-manual/basic-element/sql-data-types/conversion/float-double-conversion",
+
"sql-manual/basic-element/sql-data-types/conversion/int-conversion",
"sql-manual/basic-element/sql-data-types/conversion/time-conversion"
]
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]