콘텐츠로 이동

Json 문자열에서 path_name으로 값을 추출합니다. 값은 String으로 반환되며, 인수 중 하나라도 NULL이면 NULL이 반환됩니다. 이 함수는 to_varchar(GET_PATH(PARSE_JSON(JSON), PATH_NAME))와 같습니다.

func.json_extract_path_text(<expr>, <path_name>)
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 │
└──────────────────────────────────────────────────────────────────────────────┘
JSON_EXTRACT_PATH_TEXT( <expr>, <path_name> )
인수 설명
<expr> Json 문자열 값
<path_name> 필드 이름을 이어 붙인 문자열 값

문자열

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