Querying top-level JSON data
With Postgres JSON, querying semi-structured data is a breeze! Postgres provides built-in operators, including ->
and ->>
. In this example, you'll practice using these operators to query review data from a column of type JSON. This table takes the form below:
To give you a head-start, pandas
has been imported as pd
, and a connection object has been created and stored in the db_engine
variable. Have fun!
Diese Übung ist Teil des Kurses
Introduction to NoSQL
Anleitung zur Übung
- Use the
->
operator to query thelocation
field from thereview
column in thenested_reviews
table, as JSON. - Query the
statement
field as text from thereview
column in thenested_reviews
table. - Execute the query using
pandas
, and print the result.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Build the query to select the review_id and rating fields
query = """
SELECT
____ -> '____' AS location,
____ ____ '_____' AS statement
FROM ____;
"""
# Execute the query, render results
data = pd.____(____, db_engine)
print(____)