跳到主要内容

JSON_EXISTS_PATH

描述

用来判断 json_path 指定的字段在 JSON 数据中是否存在,如果存在返回 TRUE,不存在返回 FALSE

语法

JSON_EXISTS_PATH (<json_str>,  <path>)

别名

  • JSONB_EXISTS_PATH

参数

参数描述
<json_str>要检查的 JSON 字符串。如果是 NULL,则返回 NULL
<path>要判断是否存在的 JSON 路径。如果是 NULL,则返回 NULL

返回值

如果存在返回 TRUE,不存在返回 FALSE

举例

SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.name');
+---------------------------------------------------------------------------+
| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.name') |
+---------------------------------------------------------------------------+
| 1 |
+---------------------------------------------------------------------------+
SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.age');
+--------------------------------------------------------------------------+
| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.age') |
+--------------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------------+
SELECT JSONB_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.age');
+--------------------------------------------------------------------------+
| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.age') |
+--------------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------------+