Files
greptimedb/tests/cases/standalone/common/function/json/json.sql
Kaifeng Zheng 1a02fc31c2 fix: json_path_exists null results (#4881)
* fix: result of nulls

* update test result

* fix null behaviors, add null tests

* update NULL tests

* error handler when parsing json_path

* change the logic to: items' datatype in the input arrays are all the same.

* remove a comment

* refactor: better logic

* drop unnecessary err check

* added an error test case
2024-11-08 03:01:45 +00:00

29 lines
838 B
SQL

--- json_path_exists ---
SELECT json_path_exists(parse_json('{"a": 1, "b": 2}'), '$.a');
SELECT json_path_exists(parse_json('{"a": 1, "b": 2}'), '$.c');
SELECT json_path_exists(parse_json('[1, 2]'), '[0]');
SELECT json_path_exists(parse_json('[1, 2]'), '[2]');
SELECT json_path_exists(parse_json('[1, 2]'), 'null');
SELECT json_path_exists(parse_json('null'), '$.a');
SELECT json_path_exists(NULL, '$.a');
SELECT json_path_exists(parse_json('{}'), NULL);
--- json_path_match ---
SELECT json_path_match(parse_json('{"a": 1, "b": 2}'), '$.a == 1');
SELECT json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1');
SELECT json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[1 to last] >= 2');
SELECT json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), 'null');
SELECT json_path_match(parse_json('null'), '$.a == 1');