You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md
+112-7Lines changed: 112 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,32 +26,34 @@ under the License.
26
26
27
27
## Description
28
28
29
-
Use the first parameter sep as the connector to concatenate the second parameter and all subsequent parameters (or all strings in ARRAY) into a string. Special cases:
29
+
Use the first parameter sep as the connector to concatenate the second parameter and all subsequent parameters (or all strings in one ARRAY or multi ARRAY ) into a string. Special cases:
30
30
31
31
- If the separator is NULL, NULL is returned.
32
32
33
-
The `CONCAT_WS` function does not skip empty strings, but skips NULL values.
34
-
33
+
- The `CONCAT_WS` function does not skip empty strings, but skips NULL values.
34
+
- The `CONCAT_WS` function does not skip empty strings in any `ARRAY` parameters, but skips NULL values in `ARRAY` or - - parameters.
35
+
- The first parameters must be a `string` type, and the others must be the same type ,belong to the `string` or `ARRAY` type
35
36
## Syntax
36
37
37
38
```sql
38
39
CONCAT_WS ( <sep> , <str> [ , <str> ] )
39
-
CONCAT_WS ( <sep> , <array> )
40
+
CONCAT_WS ( <sep> , <array>[ , <array> ])
40
41
```
41
42
42
43
## Parameters
43
44
44
45
| Parameter | Description |
45
46
|-------|-----------------|
46
-
|`<sep>`| Connector for concatenating strings |
47
-
|`<str>`| String to be concatenated |
48
-
|`<array>`| Array to be concatenated |
47
+
|`<sep>`| Connector for concatenating strings, it is `string` type or `varchar` type|
48
+
|`<str>`| String to be concatenated , it is `string` or `varchar` type|
49
+
|`<array>`| Array to be concatenated ,it is `ARRAY` type, and every element is `string` or `varchar` type|
49
50
50
51
## Return value
51
52
52
53
Parameter `<sep>` or `<array>` The string concatenated with `<str>`. Special cases:
53
54
54
55
- If delimiter is NULL, returns NULL.
56
+
- If parameters with mutlti arrays and it contains a null,function will return empty string.
ERROR 1105 (HY000): errCode =2, detailMessage = can not cast from origin type ARRAY<VARCHAR(1)> to target type=VARCHAR(65533)
129
+
130
+
```
131
+
132
+
All NULL inputs
133
+
134
+
```sql
135
+
mysql>SELECT CONCAT_WS("x", NULL, NULL);
136
+
137
+
+----------------------------+
138
+
| CONCAT_WS("x", NULL, NULL) |
139
+
+----------------------------+
140
+
| |
141
+
+----------------------------+
142
+
```
143
+
144
+
Chiese Charactors concat
145
+
146
+
```sql
147
+
mysql>SELECT CONCAT_WS("x", '中文', '中文');
148
+
149
+
+------------------------------------+
150
+
| CONCAT_WS("x", '中文', '中文') |
151
+
+------------------------------------+
152
+
| 中文x中文 |
153
+
+------------------------------------+
154
+
```
155
+
156
+
Chinese charactors in multi arrays
157
+
158
+
```sql
159
+
mysql>SELECT CONCAT_WS("x", ['中文'], ['中文']);
160
+
+----------------------------------------+
161
+
| CONCAT_WS("x", ['中文'], ['中文']) |
162
+
+----------------------------------------+
163
+
| 中文x中文 |
164
+
+----------------------------------------+
165
+
```
166
+
167
+
Insert and concat them
168
+
169
+
```sql
170
+
DROPTABLE IF EXISTS test_concat_ws_1;
171
+
172
+
CREATETABLEtest_concat_ws_1 (id INT, a ARRAY<VARCHAR>, b ARRAY<VARCHAR>) ENGINE=OLAP DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num'='1')
173
+
174
+
INSERT INTO test_concat_ws_1 VALUES (1, ['a','b'], ['css',null,'d']), (2, ['x',null], ['y','z']),(3,['你好','世界'],['Doris',null,'Nereids'])
175
+
176
+
SELECT concat_ws('-', a, b) FROM test_concat_ws_1 ORDER BY id
Copy file name to clipboardExpand all lines: i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md
ERROR 1105 (HY000): errCode =2, detailMessage = can not cast from origin type ARRAY<VARCHAR(1)> to target type=VARCHAR(65533)
127
+
128
+
```
129
+
130
+
全为 NULL 的输入
131
+
132
+
```sql
133
+
mysql>SELECT CONCAT_WS("x", NULL, NULL);
134
+
135
+
+----------------------------+
136
+
| CONCAT_WS("x", NULL, NULL) |
137
+
+----------------------------+
138
+
| |
139
+
+----------------------------+
140
+
```
141
+
142
+
Chiese Charactors concat
143
+
144
+
```sql
145
+
mysql>SELECT CONCAT_WS("x", '中文', '中文');
146
+
147
+
+------------------------------------+
148
+
| CONCAT_WS("x", '中文', '中文') |
149
+
+------------------------------------+
150
+
| 中文x中文 |
151
+
+------------------------------------+
152
+
```
153
+
154
+
中文字符拼接
155
+
156
+
```sql
157
+
mysql>SELECT CONCAT_WS("x", ['中文'], ['中文']);
158
+
+----------------------------------------+
159
+
| CONCAT_WS("x", ['中文'], ['中文']) |
160
+
+----------------------------------------+
161
+
| 中文x中文 |
162
+
+----------------------------------------+
163
+
```
164
+
165
+
插入数据并拼接
166
+
167
+
```sql
168
+
DROPTABLE IF EXISTS test_concat_ws_1;
169
+
170
+
CREATETABLEtest_concat_ws_1 (id INT, a ARRAY<VARCHAR>, b ARRAY<VARCHAR>) ENGINE=OLAP DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num'='1')
171
+
172
+
INSERT INTO test_concat_ws_1 VALUES (1, ['a','b'], ['css',null,'d']), (2, ['x',null], ['y','z']),(3,['你好','世界'],['Doris',null,'Nereids'])
173
+
174
+
SELECT concat_ws('-', a, b) FROM test_concat_ws_1 ORDER BY id
0 commit comments