跳转到主内容
跳转到主内容

distinctJSONPaths

distinctJSONPaths

引入版本:v24.9

计算存储在 JSON 列中的唯一路径列表。

语法

distinctJSONPaths(json)

参数

  • json — JSON 列。JSON

返回值

返回已排序的路径列表。Array(String)

示例

带嵌套 JSON 的基本用法

DROP TABLE IF EXISTS test_json;
CREATE TABLE test_json(json JSON) ENGINE = Memory;
INSERT INTO test_json VALUES ('{"a" : 42, "b" : "Hello"}'), ('{"b" : [1, 2, 3], "c" : {"d" : {"e" : "2020-01-01"}}}'), ('{"a" : 43, "c" : {"d" : {"f" : [{"g" : 42}]}}}');

SELECT distinctJSONPaths(json) FROM test_json;
┌─distinctJSONPaths(json)───┐
│ ['a','b','c.d.e','c.d.f'] │
└───────────────────────────┘

使用显式声明的 JSON 路径

DROP TABLE IF EXISTS test_json;
CREATE TABLE test_json(json JSON) ENGINE = Memory;
INSERT INTO test_json VALUES ('{"a" : 42, "b" : "Hello"}'), ('{"b" : [1, 2, 3], "c" : {"d" : {"e" : "2020-01-01"}}}'), ('{"a" : 43, "c" : {"d" : {"f" : [{"g" : 42}]}}}')

SELECT distinctJSONPaths(json) FROM test_json;
┌─distinctJSONPaths(json)─┐
│ ['a','b','c']           │
└─────────────────────────┘