開始使用免費開始

使用 Postgres JSON 篩選文件型資料庫

透過 Postgres JSON,你可以用 ->->> 運算子來查詢與篩選儲存在文件中的資料。這一題要練習用 Postgres JSON 來篩選評論資料。和之前類似,nested_reviews 資料表的結構如下,且已為你設定好一個 sqlalchemy 連線物件,可由變數 db_engine 取得。此外,已將 pandas 載入為 pd

nested_reviews table, showing sample data.

本練習屬於課程

NoSQL 入門

檢視課程

練習說明

  • 使用 Postgres JSON,針對 nested_reviews 資料表中的每筆紀錄,擷取 review 欄位裡 statement 鍵所儲存的值。
  • 只回傳 review 欄位之 location 物件中巢狀的 branch 等於 'Disneyland_California' 的結果。

動手互動練習

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

# Build the query to select the rid and rating fields
query = """
SELECT
	review ____ '____' AS customer_review 
FROM nested_reviews 
WHERE review ____ '____' ____ '____' = 'Disneyland_California';
"""

# Execute the query, render results
data = pd.read_sql(query, db_engine)
print(data)
編輯並執行程式碼