-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1124 from yangj1211/json_extract
add doc of json_extract_float64 and json_extract_string
- Loading branch information
Showing
7 changed files
with
164 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
docs/MatrixOne/Reference/Functions-and-Operators/Json/json_extract_float64.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# **JSON_EXTRACT_FLOAT64()** | ||
|
||
## **函数说明** | ||
|
||
`JSON_EXTRACT_FLOAT64()` 用于从 JSON 数据中提取指定路径的数值的值。 | ||
|
||
如果在 where 条件中进行比较: | ||
|
||
- 如果类型为 json 对象比较,使用 [JSON EXTRACT()](./json_extract.md); | ||
- 如果类型是字符串类型,使用 [JSON_EXTRACT_STRING()](./json_extract_string.md); | ||
- 如果类型为 float 或者 int,使用 `JSON_EXTRACT_FLOAT64()`。 | ||
|
||
## **语法结构** | ||
|
||
```sql | ||
select col_name from tab_name where json_extract_float64(jsonDoc, pathExpression)= number; | ||
``` | ||
|
||
## **参数释义** | ||
|
||
| 参数 | 说明 | | ||
| ---- | ---- | | ||
| jsonDoc | 这是包含 JSON 数据的列或表达式。| | ||
| pathExpression | 表示在 JSON 文档中访问某个值的路径。一次只能接收一个路径,路径以 `$` 开始,表示 JSON 文档的根,后面可以跟随点号 `.` 和键名或用方括号 [ ] 访问数组的元素。| | ||
| number | 指定 JSON 数据中要提取的值,为数值类型。 | | ||
|
||
路径表达式必须以 `$` 字符开头: | ||
|
||
- `,` 后跟键名,使用给定键命名对象中的成员。键名需要使用双引号包含。 | ||
|
||
- `[N]`:选择数组的 *path* 后,将数组中位置 `N` 处的值命名。数组位置是从零开始的整数。如果数组是负数,则产生报错。 | ||
|
||
- 路径可以包含 `*` 或 `**` 通配符: | ||
|
||
+ `.[*]` 计算 JSON 对象中所有成员的值。 | ||
|
||
+ `[*]` 计算 JSON 数组中所有元素的值。 | ||
|
||
+ `prefix**suffix`:计算以命名前缀开头并以命名后缀结尾的所有路径。 | ||
|
||
- 文档中不存在的路径(或不存在的数据)评估为 `NULL`。 | ||
|
||
## **示例** | ||
|
||
```sql | ||
create table student(n1 int,n2 json); | ||
insert into student values | ||
(1,'{"name": "tom", "age": 18, "score": 90,"gender": "male"}'), | ||
(2,'{"name": "bob", "age": 20, "score": 80,"gender": "male"}'), | ||
(3,'{"name": "jane", "age": 17, "score": 95,"gender": "female"}'), | ||
(4,'{"name": "lily", "age": 19, "score": 79,"gender": "female"}'); | ||
|
||
mysql> select n1 from student where json_extract_float64(n2,'$.age')=19; | ||
+------+ | ||
| n1 | | ||
+------+ | ||
| 4 | | ||
+------+ | ||
1 row in set (0.00 sec) | ||
|
||
select json_extract_float64(n2,'$.age')=19; | ||
``` |
71 changes: 71 additions & 0 deletions
71
docs/MatrixOne/Reference/Functions-and-Operators/Json/json_extract_string.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# **JSON_EXTRACT_FLOAT64()** | ||
|
||
## **函数说明** | ||
|
||
`JSON_EXTRACT_FLOAT64()` 用于从 JSON 数据中提取指定路径的数值的值。 | ||
|
||
如果在 where 条件中进行比较: | ||
|
||
- 如果类型为 json 对象比较,使用 [JSON EXTRACT()](./json_extract.md); | ||
- 如果类型是字符串类型,使用 [JSON_EXTRACT_STRING()](./json_extract_string.md); | ||
- 如果类型为 float 或者 int,使用 `JSON_EXTRACT_FLOAT64()`。 | ||
|
||
## **语法结构** | ||
|
||
```sql | ||
select col_name from tab_name where json_extract_float64(jsonDoc, pathExpression)= number; | ||
``` | ||
|
||
## **参数释义** | ||
|
||
| 参数 | 说明 | | ||
| ---- | ---- | | ||
| jsonDoc | 这是包含 JSON 数据的列或表达式。| | ||
| pathExpression | 表示在 JSON 文档中访问某个值的路径。一次只能接收一个路径,路径以 `$` 开始,表示 JSON 文档的根,后面可以跟随点号 `.` 和键名或用方括号 [ ] 访问数组的元素。| | ||
| number | 指定 JSON 数据中要提取的值,为数值类型。 | | ||
|
||
路径表达式必须以 `$` 字符开头: | ||
|
||
- `,` 后跟键名,使用给定键命名对象中的成员。键名需要使用双引号包含。 | ||
|
||
- `[N]`:选择数组的 *path* 后,将数组中位置 `N` 处的值命名。数组位置是从零开始的整数。如果数组是负数,则产生报错。 | ||
|
||
- 路径可以包含 `*` 或 `**` 通配符: | ||
|
||
+ `.[*]` 计算 JSON 对象中所有成员的值。 | ||
|
||
+ `[*]` 计算 JSON 数组中所有元素的值。 | ||
|
||
+ `prefix**suffix`:计算以命名前缀开头并以命名后缀结尾的所有路径。 | ||
|
||
- 文档中不存在的路径(或不存在的数据)评估为 `NULL`。 | ||
|
||
## **示例** | ||
|
||
```sql | ||
create table student(n1 int,n2 json); | ||
insert into student values | ||
(1,'{"name": "tom", "age": 18, "score": 90,"gender": "male"}'), | ||
(2,'{"name": "bob", "age": 20, "score": 80,"gender": "male"}'), | ||
(3,'{"name": "jane", "age": 17, "score": 95,"gender": "female"}'), | ||
(4,'{"name": "lily", "age": 19, "score": 79,"gender": "female"}'); | ||
|
||
mysql> select n1 from student where json_extract_float64(n2,'$.age')=19; | ||
+------+ | ||
| n1 | | ||
+------+ | ||
| 4 | | ||
+------+ | ||
1 row in set (0.00 sec) | ||
|
||
mysql> select json_extract_float64(n2,'$.age')=19 from student; | ||
+--------------------------------------+ | ||
| json_extract_float64(n2, $.age) = 19 | | ||
+--------------------------------------+ | ||
| false | | ||
| false | | ||
| false | | ||
| true | | ||
+--------------------------------------+ | ||
4 rows in set (0.00 sec) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters