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 055def00559 docs: add boolean conversion documentation (#2650)
055def00559 is described below
commit 055def00559abc6e964ab90b372e96885cbeca78
Author: Mryange <[email protected]>
AuthorDate: Tue Jul 22 17:34:27 2025 +0800
docs: add boolean conversion documentation (#2650)
## Versions
- [x] dev
- [ ] 3.0
- [ ] 2.1
- [ ] 2.0
## Languages
- [x] Chinese
- [x] English
## Docs Checklist
- [ ] Checked by AI
- [ ] Test Cases Built
---
.../conversion/boolean-conversion.md | 141 +++++++++++++++++++++
.../conversion/boolean-conversion.md | 141 +++++++++++++++++++++
sidebars.json | 1 +
3 files changed, 283 insertions(+)
diff --git
a/docs/sql-manual/basic-element/sql-data-types/conversion/boolean-conversion.md
b/docs/sql-manual/basic-element/sql-data-types/conversion/boolean-conversion.md
new file mode 100644
index 00000000000..606a0c30198
--- /dev/null
+++
b/docs/sql-manual/basic-element/sql-data-types/conversion/boolean-conversion.md
@@ -0,0 +1,141 @@
+---
+{
+ "title": "Cast to BOOLEAN",
+ "language": "en"
+}
+---
+
+The BOOLEAN type represents true or false values, with only two possible
states: true value and false value.
+
+## FROM String
+
+:::caution Behavior Change
+Previously, strings like '1.11' could be cast to boolean type 'true', starting
from 4.0, they will be converted to null (in non-strict mode) or report an
error (in strict mode).
+Previously, values like 'on', 'off', 'yes', 'no' would be converted to null,
starting from 4.0, they can be converted to their corresponding boolean values.
+:::
+
+### Strict Mode
+
+#### BNF Definition
+
+```xml
+<boolean> ::= <whitespace>* <bool_like> <whitespace>*
+
+<bool_like> ::= "0" | "1" | "t" | "T" | "f" | "F" | <yes> | <no> | <on> |
<off> | <true> | <false>
+
+<yes> ::= ("y" | "Y") ("e" | "E") ("s" | "S")
+
+<no> ::= ("n" | "N") ("o" | "O")
+
+<on> ::= ("o" | "O") ("n" | "N")
+
+<off> ::= ("o" | "O") ("f" | "F") ("f" | "F")
+
+<true> ::= ("t" | "T") ("r" | "R") ("u" | "U") ("e" | "E")
+
+<false> ::= ("f" | "F") ("a" | "A") ("l" | "L") ("s" | "S") ("e" | "E")
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+```
+
+#### Rule Description
+
+Boolean values can be in the following forms: 0, 1, yes, no, on, off, true,
false, and are case insensitive. Additionally, boolean values can contain any
number of whitespace characters before and after (including spaces, tabs,
newlines, etc.).
+
+For formats that do not conform, an error is reported.
+
+#### Examples
+
+| String | Cast as bool Result | Comment |
+| --- | --- | --- |
+| "true" | true | |
+| "false" | false | |
+| " \t\r\n\f\v true \t\r\n\f\v" | true | With leading and trailing whitespace |
+| "1.1" | Error | Invalid format |
+| "YeS" | true | Case insensitive |
+| '+0' | Error | Invalid format |
+
+### Non-Strict Mode
+
+#### BNF Definition
+
+```xml
+<boolean> ::= <whitespace>* <bool_like> <whitespace>*
+
+<bool_like> ::= "0" | "1" | "t" | "T" | "f" | "F" | <yes> | <no> | <on> |
<off> | <true> | <false>
+
+<yes> ::= ("y" | "Y") ("e" | "E") ("s" | "S")
+
+<no> ::= ("n" | "N") ("o" | "O")
+
+<on> ::= ("o" | "O") ("n" | "N")
+
+<off> ::= ("o" | "O") ("f" | "F") ("f" | "F")
+
+<true> ::= ("t" | "T") ("r" | "R") ("u" | "U") ("e" | "E")
+
+<false> ::= ("f" | "F") ("a" | "A") ("l" | "L") ("s" | "S") ("e" | "E")
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+```
+
+#### Rule Description
+
+Boolean values can be in the following forms: 0, 1, yes, no, on, off, true,
false, and are case insensitive. Additionally, boolean values can contain any
number of whitespace characters before and after (including spaces, tabs,
newlines, etc.).
+
+For formats that do not conform, null is returned.
+
+#### Examples
+
+| String | Cast as bool Result | Comment |
+| --- | --- | --- |
+| "true" | true | |
+| "false" | false | |
+| " \t\r\n\f\v true \t\r\n\f\v" | true | With leading and trailing whitespace |
+| "1.1" | null | Invalid format |
+| "YeS" | true | Case insensitive |
+| '+0' | null | Invalid format |
+
+## FROM Numeric
+
+:::caution Behavior Change
+Previously, non-numeric types like date/datetime were allowed to be converted
to boolean type, starting from 4.0, this is not supported.
+:::
+
+### Strict Mode
+
+#### Rule Description
+
+For numeric types (int/double/decimal), non-zero values are considered true.
+
+Positive and negative zeros in floating point numbers are converted to false.
+
+#### Examples
+
+| Numeric Type | Cast as bool Result | Comment |
+| --- | --- | --- |
+| 121231 | true | |
+| 0 | false | |
+| +0.0 | false | Positive zero in floating point |
+| -0.0 | false | Negative zero in floating point |
+| -1 | true | |
+| 1 | true | |
+
+### Non-Strict Mode
+
+#### Rule Description
+
+For numeric types (int/double/decimal), non-zero values are considered true.
+
+Positive and negative zeros in floating point numbers are converted to false.
+
+#### Examples
+
+| Numeric Type | Cast as bool Result | Comment |
+| --- | --- | --- |
+| 121231 | true | |
+| 0 | false | |
+| +0.0 | false | Positive zero in floating point |
+| -0.0 | false | Negative zero in floating point |
+| -1 | true | |
+| 1 | true | |
\ 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/boolean-conversion.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/boolean-conversion.md
new file mode 100644
index 00000000000..39ee763edba
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/conversion/boolean-conversion.md
@@ -0,0 +1,141 @@
+---
+{
+ "title": "转换为 BOOLEAN",
+ "language": "zh-CN"
+}
+---
+
+BOOLEAN 类型表示真值或非真值,只有两种可能的值:真值和非真值。
+
+## FROM String
+
+:::caution 行为变更
+过去例如'1.11' 的字符串,可以被 cast 成布尔类型 'true',自 4.0 开始会转换成 null(非严格模式下) 或者报错 (严格模式下)。
+过去对于'on' , 'off' ,'yes' , 'no' 等会被转换成 null,自 4.0 开始可以转换成对应的布尔值。
+:::
+
+### 严格模式
+
+#### BNF 定义
+
+```xml
+<boolean> ::= <whitespace>* <bool_like> <whitespace>*
+
+<bool_like> ::= "0" | "1" | "t" | "T" | "f" | "F" | <yes> | <no> | <on> |
<off> | <true> | <false>
+
+<yes> ::= ("y" | "Y") ("e" | "E") ("s" | "S")
+
+<no> ::= ("n" | "N") ("o" | "O")
+
+<on> ::= ("o" | "O") ("n" | "N")
+
+<off> ::= ("o" | "O") ("f" | "F") ("f" | "F")
+
+<true> ::= ("t" | "T") ("r" | "R") ("u" | "U") ("e" | "E")
+
+<false> ::= ("f" | "F") ("a" | "A") ("l" | "L") ("s" | "S") ("e" | "E")
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+```
+
+#### 规则描述
+
+布尔值可以是以下几种形式:0、1、yes、no、on、off、true、false,并且对大小写不敏感(忽略大小写)。此外,布尔值的前后可以包含任意数量的空白字符(包括空格、制表符、换行符等)。
+
+对于不满足的格式,报错。
+
+#### 例子
+
+| 字符串 | Cast as bool 结果 | Comment |
+| --- | --- | --- |
+| "true" | 真值 | |
+| "false" | 非真值 | |
+| " \t\r\n\f\v true \t\r\n\f\v" | 真值 | 带前缀和后缀空白字符 |
+| "1.1" | 报错 | 非法格式 |
+| "YeS" | 真值 | 忽略大小写 |
+| '+0' | 报错 | 非法格式 |
+
+### 非严格模式
+
+#### BNF 定义
+
+```xml
+<boolean> ::= <whitespace>* <bool_like> <whitespace>*
+
+<bool_like> ::= "0" | "1" | "t" | "T" | "f" | "F" | <yes> | <no> | <on> |
<off> | <true> | <false>
+
+<yes> ::= ("y" | "Y") ("e" | "E") ("s" | "S")
+
+<no> ::= ("n" | "N") ("o" | "O")
+
+<on> ::= ("o" | "O") ("n" | "N")
+
+<off> ::= ("o" | "O") ("f" | "F") ("f" | "F")
+
+<true> ::= ("t" | "T") ("r" | "R") ("u" | "U") ("e" | "E")
+
+<false> ::= ("f" | "F") ("a" | "A") ("l" | "L") ("s" | "S") ("e" | "E")
+
+<whitespace> ::= " " | "\t" | "\n" | "\r" | "\f" | "\v"
+```
+
+#### 规则描述
+
+布尔值可以是以下几种形式:0、1、yes、no、on、off、true、false,并且对大小写不敏感(忽略大小写)。此外,布尔值的前后可以包含任意数量的空白字符(包括空格、制表符、换行符等)。
+
+对于不满足的格式,返回 null。
+
+#### 例子
+
+| 字符串 | Cast as bool 结果 | Comment |
+| --- | --- | --- |
+| "true" | 真值 | |
+| "false" | 非真值 | |
+| " \t\r\n\f\v true \t\r\n\f\v" | 真值 | 带前缀和后缀空白字符 |
+| "1.1" | null | 非法格式 |
+| "YeS" | 真值 | 忽略大小写 |
+| '+0' | null | 非法格式 |
+
+## FROM Numeric
+
+:::caution 行为变更
+过去允许 date/datetime 等非数字类型转换成布尔类型,自 4.0 开始不支持。
+:::
+
+### 严格模式
+
+#### 规则描述
+
+对于数字类型(int/double/decimal),判断非 0 为 true。
+
+浮点数的正负 0 会转换成 false。
+
+#### 例子
+
+| 数字类型 | Cast as bool 结果 | Comment |
+| --- | --- | --- |
+| 121231 | 真值 | |
+| 0 | 非真值 | |
+| +0.0 | 非真值 | 浮点数正 0 |
+| -0.0 | 非真值 | 浮点数负 0 |
+| -1 | 真值 | |
+| 1 | 真值 | |
+
+### 非严格模式
+
+#### 规则描述
+
+对于数字类型(int/double/decimal),判断非 0 为 true。
+
+浮点数的正负 0 会转换成 false。
+
+#### 例子
+
+| 数字类型 | Cast as bool 结果 | Comment |
+| --- | --- | --- |
+| 121231 | 真值 | |
+| 0 | 非真值 | |
+| +0.0 | 非真值 | 浮点数正 0 |
+| -0.0 | 非真值 | 浮点数负 0 |
+| -1 | 真值 | |
+| 1 | 真值 | |
\ No newline at end of file
diff --git a/sidebars.json b/sidebars.json
index c9da8ba490b..d172cda51e8 100644
--- a/sidebars.json
+++ b/sidebars.json
@@ -1025,6 +1025,7 @@
"type": "category",
"label": "Conversion",
"items": [
+
"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/time-conversion"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]