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

शीर्ष-स्तरीय JSON keys निकालना

Idaho की फील्ड टीम फिर सक्रिय है. उनके पास नया weather station है जो JSON strings आउटपुट करता है, जिनसे वे आपसे डेटा निकालने में मदद चाहते हैं. आपके लिए JSON weather_station नामक CTE में दिया गया है. इसमें JSON string 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 ___;
कोड संपादित करें और चलाएँ