JSON_ARRAY_ELEMENTS (Lakehouse v1)
JSON 배열의 요소를 추출해 결과 집합에 개별 행으로 반환합니다. JSON_ARRAY_ELEMENTS는 중첩된 배열을 재귀적으로 확장하지 않고 하나의 요소로 취급합니다.
Analyze Syntax
섹션 제목: “Analyze Syntax”func.json_array_elements(<json_string>)Analyze Examples
섹션 제목: “Analyze Examples”func.json_array_elements(func.parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]'))┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ func.json_array_elements(func.parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]')) │├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤│ {"brand":"Apple","price":1500,"product":"Laptop"} ││ {"brand":"Samsung","price":800,"product":"Smartphone"} ││ {"brand":"Sony","price":150,"product":"Headphones"} │└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘SQL Syntax
섹션 제목: “SQL Syntax”JSON_ARRAY_ELEMENTS(<json_string>)반환 타입
섹션 제목: “반환 타입”JSON_ARRAY_ELEMENTS는 입력 JSON 배열에서 추출한 요소를 각각 나타내는 VARIANT 값의 집합을 반환합니다.
SQL Examples
섹션 제목: “SQL Examples”-- Extract individual elements from a JSON array containing product informationSELECT JSON_ARRAY_ELEMENTS( PARSE_JSON ( '[ {"product": "Laptop", "brand": "Apple", "price": 1500}, {"product": "Smartphone", "brand": "Samsung", "price": 800}, {"product": "Headphones", "brand": "Sony", "price": 150}]' ) );
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ json_array_elements(parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]')) │├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤│ {"brand":"Apple","price":1500,"product":"Laptop"} ││ {"brand":"Samsung","price":800,"product":"Smartphone"} ││ {"brand":"Sony","price":150,"product":"Headphones"} │└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
-- Display data types of the extracted elementsSELECT TYPEOF ( JSON_ARRAY_ELEMENTS( PARSE_JSON ( '[ {"product": "Laptop", "brand": "Apple", "price": 1500}, {"product": "Smartphone", "brand": "Samsung", "price": 800}, {"product": "Headphones", "brand": "Sony", "price": 150}]' ) ) );
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐│ typeof(json_array_elements(parse_json('[ \n {"product": "laptop", "brand": "apple", "price": 1500},\n {"product": "smartphone", "brand": "samsung", "price": 800},\n {"product": "headphones", "brand": "sony", "price": 150}\n]'))) │├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤│ VARIANT NULL ││ VARIANT NULL ││ VARIANT NULL │└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘