JSON_EXISTS_PATH
更新时间:2025-10-16
描述
用来判断 json_path 指定的字段在 JSON 数据中是否存在,如果存在返回 TRUE,不存在返回 FALSE
语法
SQL
1JSON_EXISTS_PATH (<json_str>, <path>)
别名
- JSONB_EXISTS_PATH
参数
| 参数 | 描述 |
|---|---|
<json_str> |
要包含在 JSON 数组中的元素。可以是任意类型的值,包括NULL。如果没有指定元素,则返回一个空数组。 |
<path> |
要插入的 JSON 路径。如果是 NULL ,则返回 NULL |
返回值
如果存在返回 TRUE,不存在返回 FALSE
举例
SQL
1SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.name');
Text
1+---------------------------------------------------------------------------+
2| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.name') |
3+---------------------------------------------------------------------------+
4| 1 |
5+---------------------------------------------------------------------------+
SQL
1SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.age');
Text
1+--------------------------------------------------------------------------+
2| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.age') |
3+--------------------------------------------------------------------------+
4| 0 |
5+--------------------------------------------------------------------------+
SQL
1SELECT JSONB_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.age');
Text
1+--------------------------------------------------------------------------+
2| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.age') |
3+--------------------------------------------------------------------------+
4| 0 |
5+--------------------------------------------------------------------------+
