JSON_EXTRACT_PATH_TEXT (Lakehouse v1)
Extrai o valor de uma string Json por path_name.
O valor é retornado como String, ou NULL se qualquer um dos argumentos for NULL.
Esta função equivale a to_varchar(GET_PATH(PARSE_JSON(JSON), PATH_NAME)).
Sintaxe do Analyze
Seção intitulada “Sintaxe do Analyze”func.json_extract_path_text(<expr>, <path_name>)Exemplos do Analyze
Seção intitulada “Exemplos do 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 │└──────────────────────────────────────────────────────────────────────────────┘Sintaxe SQL
Seção intitulada “Sintaxe SQL”JSON_EXTRACT_PATH_TEXT( <expr>, <path_name> )Argumentos
Seção intitulada “Argumentos”| Argumentos | Descrição |
|---|---|
<expr> |
O valor String Json |
<path_name> |
O valor String que consiste em uma concatenação de nomes de campo |
Tipo de retorno
Seção intitulada “Tipo de retorno”String
Exemplos de SQL
Seção intitulada “Exemplos de 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 │└─────────────────────────────────────────────────────────────────────────┘