開始使用免費開始

在 Snowflake 查詢半結構化資料

在 Snowflake 中,半結構化資料可以用最原始的形式儲存。這裡,我們把少數幾個奧運主辦城市的資訊,存放在 host_cities 資料表的 city_meta 欄位中。此欄位的型別為 VARIANT,可讓非結構化資料儲存在同一個欄位。資料的形式如下:

Snowflake table with a single column of type VARIANT.

在這個練習中,你會同時用中括號與點記號來查詢這些資料。已為你建立 olympics 資料庫的連線物件 conn。加油!

本練習屬於課程

NoSQL 入門

檢視課程

練習說明

  • 使用點記號,從 host_cities 資料表的 city_meta 欄位擷取 city 欄位。
  • 使用點記號,從 host_cities 資料表的 city_meta 欄位查詢巢狀的 country 欄位。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Build a query to pull city and country names
query = """
SELECT
	city_meta:____,
    ____:____
FROM host_cities;
"""

# Execute query and output results
results = conn.cursor().execute(query).fetch_pandas_all()
print(results)
編輯並執行程式碼