Filtering document databases with Postgres JSON
Using Postgres JSON, data stored in documents can be queried and filtered using the ->
and ->>
operators. To practice, you'll filter reviews using Postgres JSON. Similar to before, the nested_reviews
table takes the form below, and a sqlalchemy
connection object has been configured, and made available for you via the db_engine
variable. pandas
has also been loaded as pd
.
Diese Übung ist Teil des Kurses
Introduction to NoSQL
Anleitung zur Übung
- Use Postgres JSON to retrieve the value stored at the
statement
key in thereview
column, for each record in thenested_reviews
table. - Only return results with a
branch
nested in thelocation
object of thereview
column equal to'Disneyland_California'
.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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)