Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs/sql-manual/sql-statements/table-and-view/table/DESC-TABLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ Users executing this SQL command must have at least the following permissions:

## Examples

Setup — create the `test_table` used by the examples below:

```sql
CREATE TABLE test_table (
user_id BIGINT NOT NULL COMMENT 'Key1',
name VARCHAR(20) COMMENT 'username',
age INT COMMENT 'user_age'
) ENGINE=OLAP
UNIQUE KEY (user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 1
PROPERTIES ("replication_num" = "1");
```

1. Display Base Table Schema

```sql
Expand All @@ -99,3 +112,35 @@ DESC test_table;
| age | int | Yes | false | NULL | NONE |
+---------+-------------+------+-------+---------+-------+
```

Set `show_column_comment_in_describe = true` (introduced in 3.0.7) to add the `Comment` column to the output:

```sql
SET show_column_comment_in_describe=true;
DESC test_table;
```
```text
+---------+-------------+------+-------+---------+-------+----------+
| Field | Type | Null | Key | Default | Extra | Comment |
+---------+-------------+------+-------+---------+-------+----------+
| user_id | bigint | No | true | NULL | | Key1 |
| name | varchar(20) | Yes | false | NULL | NONE | username |
| age | int | Yes | false | NULL | NONE | user_age |
+---------+-------------+------+-------+---------+-------+----------+
```

2. Display the Schema of All Indexes of a Table

```sql
DESC test_table ALL;
```

```text
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+
| IndexName | IndexKeysType | Field | Type | InternalType | Null | Key | Default | Extra | Visible | DefineExpr | WhereClause |
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+
| test_table | UNIQUE_KEYS | user_id | bigint | bigint | No | true | NULL | | true | | |
| | | name | varchar(20) | varchar(20) | Yes | false | NULL | NONE | true | | |
| | | age | int | int | Yes | false | NULL | NONE | true | | |
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## 语法

```text
```sql
COLLECT_LIST(<expr> [,<max_size>])
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ SELECT array_contains([1, 2, 3], 'string');
```

当查找值类型无法和数组元素进行类型转换时, 会返回错误
```
```sql
SELECT array_contains([1, 2, 3], [4, 5, 6]);
ERROR 1105 (HY000): errCode = 2, detailMessage = can not cast from origin type ARRAY<TINYINT> to target type=TINYINT
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ERROR 1105 (HY000): errCode = 2, detailMessage = lengths of all arrays of functi
```

IP 类型支持的例子
```
```sql
SELECT array_enumerate_uniq(CAST(['192.168.1.1', '192.168.1.2', '192.168.1.1'] AS ARRAY<IPV4>));
+------------------------------------------------------------------------------------------+
| array_enumerate_uniq(CAST(['192.168.1.1', '192.168.1.2', '192.168.1.1'] AS ARRAY<IPV4>)) |
Expand All @@ -124,13 +124,13 @@ mysql> SELECT array_enumerate_uniq(CAST(['2001:db8::1', '2001:db8::2', '2001:db8
复杂类型示例:

嵌套数组类型不支持,报错:
```
```sql
SELECT array_enumerate_uniq([[1,2],[3,4],[5,6]]);
ERROR 1105 (HY000): errCode = 2, detailMessage = array_enumerate_uniq does not support type ARRAY<ARRAY<TINYINT>>, expression is array_enumerate_uniq([[1, 2], [3, 4], [5, 6]])
```

map 类型不支持,报错:
```
```sql
SELECT array_enumerate_uniq([{'k':1},{'k':2},{'k':3}]);
ERROR 1105 (HY000): errCode = 2, detailMessage = array_enumerate_uniq does not support type ARRAY<MAP<VARCHAR(1),TINYINT>>, expression is array_enumerate_uniq([map('k', 1), map('k', 2), map('k', 3)])
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ SELECT array_exists(x -> x > 0, []);
```

NULL 数组和lambda 表达式组合,参数中有lambda 表达式结合NULL 会报错,无lambda 表达式则返回 NULL:
```
```sql
SELECT array_exists(NULL);
+--------------------+
| array_exists(NULL) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ SELECT array_first_index(x -> x > 0, []);
```

NULL 数组和lambda 表达式组合,参数中有lambda 表达式结合NULL 会报错,无lambda 表达式则返回 0:
```
```sql
SELECT array_first_index(NULL);
+-------------------------+
| array_first_index(NULL) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ SELECT array_first(x -> x > 0, []);
```

输入参数为NULL 会报错:
```
```sql
SELECT array_first(x -> x > 2, NULL);
ERROR 1105 (HY000): errCode = 2, detailMessage = lambda argument must be array but is NULL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ARRAYS_OVERLAP(arr1, arr2)
+----------------------------+
| NULL |
+----------------------------+
```'
```

4. 输入的`ARRAY` 包含 `NULL` 时,`NULL` 和 `NULL`被视作相等

Expand All @@ -110,7 +110,7 @@ ARRAYS_OVERLAP(arr1, arr2)
+---------------------------------------------------+
| 1 |
+---------------------------------------------------+
```'
```

5. 使用倒排索引加速查询

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ MurMur3 算法是一种高性能的、低碰撞率的散列算法,其计算出

如果你想计算某个值的 MurMur3,你可以:

```
```sql
select bitmap_to_array(bitmap_hash('hello'))[1];
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

## 语法

`to_bitmap(<expr>)`
```sql
TO_BITMAP(<expr>)
```

## 参数

Expand Down Expand Up @@ -96,7 +98,7 @@ select bitmap_to_string(to_bitmap("123ABC")),bitmap_count(to_bitmap("123ABC"));
select bitmap_to_string(to_bitmap(NULL)),bitmap_count(to_bitmap(NULL));
```

The result will be:
结果如下:

```text
+-----------------------------------+-------------------------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,49 +71,13 @@ SELECT MILLISECONDS_ADD('2023-10-01 12:00:00.500', NULL) AS after_add;
| NULL |
+-----------+

---delta 参数超过 INT 范围,返回 NULL
---delta 参数支持 BIGINT 范围,超过 INT 上限 (2^31 - 1) 时仍正常计算
SELECT MILLISECONDS_ADD('2023-09-08 16:02:08.435', 2147483648) AS after_add;
+-----------+
| after_add |
+-----------+
| NULL |
+-----------+

---增加一毫秒
SELECT MILLISECONDS_ADD('2023-09-08 16:02:08.435123', 1);
+---------------------------------------------------+
| MILLISECONDS_ADD('2023-09-08 16:02:08.435123', 1) |
+---------------------------------------------------+
| 2023-09-08 16:02:08.436123 |
+---------------------------------------------------+

---毫秒数为负数,对应日期时间减去相应毫秒数
SELECT MILLISECONDS_ADD('2023-05-01 10:00:00.800', -300);
+---------------------------------------------------+
| MILLISECONDS_ADD('2023-05-01 10:00:00.800', -300) |
+---------------------------------------------------+
| 2023-05-01 10:00:00.500000 |
+---------------------------------------------------+

--- 输入为 DATE 类型(默认时间 00:00:00.000)
SELECT MILLISECONDS_ADD('2023-01-01', 1500);
+--------------------------------------+
| MILLISECONDS_ADD('2023-01-01', 1500) |
+--------------------------------------+
| 2023-01-01 00:00:01.500000 |
+--------------------------------------+

---超出日期时间范围,抛出异常
SELECT MILLISECONDS_ADD('9999-12-31 23:59:59.999', 2000) AS after_add;
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.3)[E-218]Operation milliseconds_add of 9999-12-31 23:59:59.999000, 2000 out of range

---任意参数为 NULL,返回 NULL
SELECT MILLISECONDS_ADD('2023-10-01 12:00:00.500', NULL) AS after_add;
+-----------+
| after_add |
+-----------+
| NULL |
+-----------+
+----------------------------+
| after_add |
+----------------------------+
| 2023-10-03 12:33:32.083000 |
+----------------------------+

```

Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.123');
+-------------------------------------------+

---在1970-01-01 之前的日期时间,返回 0
select unix_timestamp('1007-11-30 10:30:19')
select unix_timestamp('1007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('1007-11-30 10:30:19') |
+---------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
WEEK 函数用于返回指定日期对应的星期数,默认 Mode 为 0,支持通过 mode 参数自定义星期计算规则(如星期的第一天是周日还是周一、星期数的范围、第一个星期的判定标准等)。
参数 mode 的作用参见下面的表格:

```sql
|Mode |星期的第一天 |星期数的范围 |第一个星期的定义 |
|:---|:-------------|:-----------|:--------------------------------------------|
|0 |星期日 |0-53 |这一年中的第一个星期日所在的星期 |
Expand All @@ -22,7 +21,6 @@ WEEK 函数用于返回指定日期对应的星期数,默认 Mode 为 0,支
|5 |星期一 |0-53 |这一年中的第一个星期一所在的星期 |
|6 |星期日 |1-53 |这一年的日期所占的天数大于等于 4 天的第一个星期|
|7 |星期一 |1-53 |这一年中的第一个星期一所在的星期 |
```

该函数与 mysql 中的 [week函数](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_week) 行为一致。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ SELECT trim_in('ababccaab', 'ab');
+----------------------------+
```

3. 与 TRIM 函数对比 —— `trim_in` 把第二个参数当作*字符集合*,从两端剥离集合中出现的任意字符;`trim` 把它当作字面*子串*,从两端剥离精确匹配。两者都会反复剥离直到两端没有可以再剥的内容。
```sql
SELECT trim_in('ababccaab', 'ab'), trim('ababccaab', 'ab');
```
```text
+----------------------------+-------------------------+
| trim_in('ababccaab', 'ab') | trim('ababccaab', 'ab') |
+----------------------------+-------------------------+
| cc | cca |
+----------------------------+-------------------------+
```

4. 字符集合顺序无关
```sql
SELECT trim_in('abcHelloabc', 'cba');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ DESC test_table;
2. 显示表所有 index 的 schema

```sql
DESC demo.test_table ALL;
DESC test_table ALL;
```

```text
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+
| IndexName | IndexKeysType | Field | Type | InternalType | Null | Key | Default | Extra | Visible | DefineExpr | WhereClause |
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+
| test_table | DUP_KEYS | user_id | bigint | bigint | No | true | NULL | | true | | |
| test_table | UNIQUE_KEYS | user_id | bigint | bigint | No | true | NULL | | true | | |
| | | name | varchar(20) | varchar(20) | Yes | false | NULL | NONE | true | | |
| | | age | int | int | Yes | false | NULL | NONE | true | | |
+------------+---------------+---------+-------------+--------------+------+-------+---------+-------+---------+------------+-------------+
Expand Down
Loading