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

本練習屬於課程
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)