LoslegenKostenlos loslegen

Querying JSON and JSONB data from Postgres

With Postgres' built-in JSON and JSONB data types, it's easy to store and interact with semi-structured data in a Postgres table. In this exercise, you'll observe some of the tooling that Postgres offers to query data of type JSON from the nested_reviews table. Best of luck!

Diese Übung ist Teil des Kurses

Introduction to NoSQL

Kurs anzeigen

Anleitung zur Übung

  • Create a connection to the disneyland database with user repl, using sqlalchemy.
  • Execute the query stored in the query variable, using the previously-defined db_engine.
  • Output the review column of the results DataFrame, and observe the data that was returned.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

import pandas as pd
import sqlalchemy

# Create a connection to the reviews database
db_engine = sqlalchemy.create_engine("postgresql+psycopg2://____:password@localhost:5432/____")

query = """SELECT * FROM nested_reviews;"""

# Execute the query, check out the results
results = pd.____(____, ____)

# Print the review column from the results DataFrame
____(results["review"])
Code bearbeiten und ausführen