최상위 JSON 키 추출하기
Idaho 현장 팀이 다시 의뢰를 보냈어요. 새 기상 관측소에서 JSON 문자열을 내보내고 있는데, 여기서 데이터를 뽑아 달라고 합니다. 작업할 수 있도록 weather_station라는 CTE에 JSON을 준비해 두었고, JSON 문자열은 data 열에 들어 있어요.
이 연습은 강의의 일부입니다
Redshift 입문
연습 안내
data에서'date'값을 추출해weather_date로 지정하세요.data에서'weather'값을 추출해weather_state로 지정하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
-- weather_station CTE with the JSON in the data column
WITH weather_station AS (
SELECT '
{
"location": "Salmon Challis National Forest",
"date": "2024-02-10",
"weather": "Rainy",
"temperature": {
"current": 10,
"min": 8,
"max": 12,
"hourly_temperature": [8, 8, 9, 9, 10, 10, 11, 11, 12]
}
}'::SUPER::VARCHAR as data
-- Above line casts to SUPER and then to
-- VARCHAR to ensure it's ready for parsing
)
-- Extract the date value
SELECT ___(___, ___) AS ___,
-- Extract the weather value
___(___, ___) AS ___
-- Using the CTE
FROM ___;