Estrazione delle chiavi JSON di primo livello
Il team sul campo dell'Idaho è di nuovo all'opera: hanno una nuova stazione meteo che produce stringhe JSON dalle quali vorrebbero che tu estraessi dei dati. Il JSON è nella CTE chiamata weather_station su cui puoi lavorare. Contiene la stringa JSON nella colonna data.
Questo esercizio fa parte del corso
Introduzione a Redshift
Istruzioni dell'esercizio
- Estrai il valore
'date'dadatacomeweather_date. - Estrai il valore
'weather'dadatacomeweather_state.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
-- 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 ___;