CommencerCommencer gratuitement

Querying nested documents with Postgres JSON

With Postgres JSON, querying semi-structured data is a breeze! Postgres provides built-in operators, such as ->. In this example, you'll practice using this operator to query reviews data from a column of type JSON. This table takes the form below:

nested_reviews table, showing sample data.

pandas has been imported as pd, and a sqlalchemy connection object has been configured, and made available for you via the db_engine variable. Best of luck!

Cet exercice fait partie du cours

Introduction to NoSQL

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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)
Modifier et exécuter le code