JSON_EXTRACT_PATH_TEXT(Lakehouse v1)
按 path_name 从 Json 字符串中提取值。
返回值为 String;如果任一参数为 NULL,则返回 NULL。
此函数等同于 to_varchar(GET_PATH(PARSE_JSON(JSON), PATH_NAME))。
Analyze 语法
Section titled “Analyze 语法”func.json_extract_path_text(<expr>, <path_name>)Analyze 示例
Section titled “Analyze 示例”func.json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k2.k4')┌──────────────────────────────────────────────────────────────────────────────┐│ func.json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k2.k4') │├──────────────────────────────────────────────────────────────────────────────┤│ 4 │└──────────────────────────────────────────────────────────────────────────────┘SQL 语法
Section titled “SQL 语法”JSON_EXTRACT_PATH_TEXT( <expr>, <path_name> )| 参数 | 说明 |
|---|---|
<expr> |
Json 字符串值 |
<path_name> |
由字段名拼接而成的字符串值 |
String
SQL 示例
Section titled “SQL 示例”SELECT json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k1[0]');┌─────────────────────────────────────────────────────────────────────────┐│ json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k1[0]') │├─────────────────────────────────────────────────────────────────────────┤│ 0 │└─────────────────────────────────────────────────────────────────────────┘
SELECT json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k2:k3');┌─────────────────────────────────────────────────────────────────────────┐│ json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k2:k3') │├─────────────────────────────────────────────────────────────────────────┤│ 3 │└─────────────────────────────────────────────────────────────────────────┘
SELECT json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k2.k4');┌─────────────────────────────────────────────────────────────────────────┐│ json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k2.k4') │├─────────────────────────────────────────────────────────────────────────┤│ 4 │└─────────────────────────────────────────────────────────────────────────┘
SELECT json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k2.k5');┌─────────────────────────────────────────────────────────────────────────┐│ json_extract_path_text('{"k1":[0,1,2], "k2":{"k3":3,"k4":4}}', 'k2.k5') │├─────────────────────────────────────────────────────────────────────────┤│ NULL │└─────────────────────────────────────────────────────────────────────────┘