1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to NoSQL

Connected

Exercise

#> and #>>

Previously, to query nested document data with Postgres JSON, you had chained the -> and ->> operators together. However, when working with deeply nested data, these statements could become long and difficult to read and troubleshoot. To remedy this, Postgres offers the #> and #>> operators. In this example, you'll practice using these operators by querying the nested_reviews table, which takes the form below:

nested_reviews table, showing sample data.

pandas has been imported as pd, and a connection object has been created and stored in the variable db_engine. Best of luck!

Instructions

100 XP
  • Use the json_typeof() function and the #> operator function to find the data type of the value stored in the statement key of the review column in the nested_reviews table.
  • Query the branch field, which is nested in the locations object, from the review column, as text. Alias the field as branch.
  • Try to return the zipcode field nested in the location object, as text, aliasing the field as zipcode.