開始使用免費開始

使用 Postgres JSON 查詢巢狀文件

使用 Postgres 的 JSON,查詢半結構化資料非常輕鬆!Postgres 提供了像 -> 這樣的內建運算子。這個例子中,你將練習使用這個運算子,從 JSON 型別的欄位中查詢 reviews 資料。此資料表的形式如下:

nested_reviews table, showing sample data.

pandas 已以 pd 匯入,sqlalchemy 連線物件也已設定完成,並透過變數 db_engine 提供給你使用。祝你順利!

本練習屬於課程

NoSQL 入門

檢視課程

動手互動練習

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

# Build the query to select the statement field
query = """
	SELECT 
    	review -> '___' AS statement
    FROM nested_reviews;
"""

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