メインコンテンツへスキップ
メインコンテンツへスキップ

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']           │
└─────────────────────────┘