IniziaInizia gratis

Querying semi-structured data in Snowflake

With Snowflake, semi-structured data can be stored in its most raw form. Here, information about a handful of Olympic host cities is stored in the city_meta column of the host_cities table. This column takes type VARIANT, allowing for unstructured data to be stored in this single column. The data takes the form below:

Snowflake table with a single column of type VARIANT.

In this exercise, you'll practice querying this data using both bracket and dot notations. A connection object conn for the olympics database has been created for you. Good luck!

Questo esercizio fa parte del corso

Introduction to NoSQL

Visualizza il corso

Istruzioni dell'esercizio

  • Use dot-notation to retrieve the city field from the city_meta column in the host_cities table.
  • Use dot-notation to query the nested country field from the city_meta column in the host_cities table.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Build a query to pull city and country names
query = """
SELECT
	city_meta:____,
    ____:____
FROM host_cities;
"""

# Execute query and output results
results = conn.cursor().execute(query).fetch_pandas_all()
print(results)
Modifica ed esegui il codice