Skip to content

Commit 23ed6d8

Browse files
Mryangedataroaring
authored andcommitted
[doc] update boolean doc (#3035)
## Versions - [x] dev - [ ] 3.x - [ ] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built
1 parent 381b09c commit 23ed6d8

2 files changed

Lines changed: 154 additions & 11 deletions

File tree

  • docs/sql-manual/basic-element/sql-data-types/numeric
  • i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/numeric

docs/sql-manual/basic-element/sql-data-types/numeric/BOOLEAN.md

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,82 @@
66
}
77
---
88

9-
## BOOLEAN
10-
### Description
11-
BOOL, BOOLEAN
12-
Like TINYINT, 0 stands for false and 1 for true.
9+
## Description
10+
11+
BOOLEAN (alias: BOOL) is a data type in Doris that represents boolean values: true and false.
12+
13+
Internally, BOOLEAN is stored as a uint8 value, where 0 represents false and 1 represents true.
14+
15+
Unlike MySQL where BOOLEAN is an alias for TINYINT(1), Doris treats BOOLEAN as a separate data type, similar to PostgreSQL, Oracle, and other database systems.
16+
17+
## Value Range
18+
19+
BOOLEAN values can only be:
20+
- `true` (represented as 1 when displayed)
21+
- `false` (represented as 0 when displayed)
22+
23+
In memory, BOOLEAN type only exists as 0 or 1, with no other possible values.
24+
25+
## Literal Values
26+
27+
In Doris, you can use the keywords `true` and `false` (case-insensitive) to represent boolean literal values:
28+
29+
```sql
30+
mysql> select TrUe, False, true;
31+
+------+-------+------+
32+
| TrUe | False | true |
33+
+------+-------+------+
34+
| 1 | 0 | 1 |
35+
+------+-------+------+
36+
```
37+
38+
## Supported Operations
39+
40+
### Logical Operations
41+
42+
BOOLEAN type supports logical operations such as AND, OR, NOT, and XOR:
1343

14-
### keywords
15-
BOOLEAN
44+
```sql
45+
mysql> select true AND false, true OR false, NOT true, true XOR false;
46+
+----------------+---------------+----------+----------------+
47+
| true AND false | true OR false | NOT true | true XOR false |
48+
+----------------+---------------+----------+----------------+
49+
| 0 | 1 | 0 | 1 |
50+
+----------------+---------------+----------+----------------+
51+
```
52+
53+
### Arithmetic Operations
54+
55+
While BOOLEAN doesn't directly support arithmetic operations, expressions like `true + true` will work due to implicit type conversion:
56+
57+
```sql
58+
mysql> select true + true;
59+
+-------------+
60+
| true + true |
61+
+-------------+
62+
| 2 |
63+
+-------------+
64+
```
65+
66+
This works because the boolean values are implicitly cast to SMALLINT: `CAST(TRUE AS smallint) + CAST(TRUE AS smallint)`.
67+
68+
## Type Conversion
69+
70+
It's important to note that BOOLEAN is not equivalent to TINYINT in Doris, even though they may appear similar due to MySQL conventions.
71+
72+
When inserting a boolean literal into a TINYINT column, implicit type conversion occurs:
73+
74+
```sql
75+
CREATE TABLE test_boolean(
76+
u8 TINYINT
77+
)
78+
properties("replication_num" = "1");
79+
80+
mysql> insert into test_boolean values(true);
81+
```
82+
83+
In this example, the boolean literal `true` is converted to a TINYINT value.
84+
85+
## Keywords
86+
87+
BOOL, BOOLEAN

i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/basic-element/sql-data-types/numeric/BOOLEAN.md

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,82 @@
66
}
77
---
88

9-
## BOOLEAN
109
## 描述
11-
BOOL, BOOLEAN
12-
与TINYINT一样,0代表false,1代表true
1310

14-
### keywords
11+
BOOLEAN 是 Doris 中表示布尔值的数据类型:真值和假值。
1512

16-
BOOLEAN
13+
在内部,BOOLEAN 被存储为 uint8 值,其中 0 表示 false(假),1 表示 true(真)。
14+
15+
与 MySQL 中 BOOLEAN 是 TINYINT(1) 的别名不同,Doris 将 BOOLEAN 作为一个独立的数据类型处理,类似于 PostgreSQL、Oracle 和其他数据库系统。
16+
17+
## 取值范围
18+
19+
BOOLEAN 值只能是:
20+
- `true`(显示时表示为 1)
21+
- `false`(显示时表示为 0)
22+
23+
在内存中,BOOLEAN 类型只存在 0 或 1,没有其他可能的值。
24+
25+
## 字面量
26+
27+
在 Doris 中,您可以使用关键字 `true``false`(不区分大小写)来表示布尔字面量:
28+
29+
```sql
30+
mysql> select TrUe, False, true;
31+
+------+-------+------+
32+
| TrUe | False | true |
33+
+------+-------+------+
34+
| 1 | 0 | 1 |
35+
+------+-------+------+
36+
```
37+
38+
## 支持的操作
39+
40+
### 逻辑运算
41+
42+
BOOLEAN 类型支持逻辑运算,如 AND、OR、NOT 和 XOR:
43+
44+
```sql
45+
mysql> select true AND false, true OR false, NOT true, true XOR false;
46+
+----------------+---------------+----------+----------------+
47+
| true AND false | true OR false | NOT true | true XOR false |
48+
+----------------+---------------+----------+----------------+
49+
| 0 | 1 | 0 | 1 |
50+
+----------------+---------------+----------+----------------+
51+
```
52+
53+
### 算术运算
54+
55+
虽然 BOOLEAN 类型不直接支持算术运算,但像 `true + true` 这样的表达式会由于隐式类型转换而生效:
56+
57+
```sql
58+
mysql> select true + true;
59+
+-------------+
60+
| true + true |
61+
+-------------+
62+
| 2 |
63+
+-------------+
64+
```
65+
66+
这是因为布尔值被隐式转换为 SMALLINT:`CAST(TRUE AS smallint) + CAST(TRUE AS smallint)`
67+
68+
## 类型转换
69+
70+
需要注意的是,在 Doris 中,BOOLEAN 与 TINYINT 不等价,尽管它们由于 MySQL 的习惯可能看起来相似。
71+
72+
当将布尔字面量插入到 TINYINT 列时,会发生隐式类型转换:
73+
74+
```sql
75+
CREATE TABLE test_boolean(
76+
u8 TINYINT
77+
)
78+
properties("replication_num" = "1");
79+
80+
mysql> insert into test_boolean values(true);
81+
```
82+
83+
在这个例子中,布尔字面量 `true` 被转换为 TINYINT 值。
84+
85+
## 关键字
86+
87+
BOOL, BOOLEAN

0 commit comments

Comments
 (0)