शुरू करेंमुफ़्त में शुरू करें

Nested JSON keys निकालना

अब field team चाहती है कि आप current temperature और 4AM का temperature निकालें। उनका कहना है कि hour_temperature key में एक array है जो 12AM या midnight से शुरू होता है। JSON फिर से आपके लिए CTE में दिया गया है.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Redshift परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Weather station data से current temperature को current_temp के रूप में extract करें.
  • Weather station data से 4AM का 'hourly_temperature' four_am_temp के रूप में extract करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

-- 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 current temperature
SELECT ___(data, ___, ___) AS current_temp,
       -- Extract the hourly_temperature at 4AM
       ___(data, ___,___, ___) as four_am_temp
  -- Use the CTE
  FROM ___;
कोड संपादित करें और चलाएँ