Skip to main content

For AI agents: a Markdown version of this page is at https://docs.snowplow.io/docs/get-started/querying.md. The index of all documentation pages is at https://docs.snowplow.io/llms.txt, and the index for this section is at https://docs.snowplow.io/docs/cdi/llms.txt.

Query your first events

Snowplow loads every validated event into one events table in your warehouse or lake, with a row per event. This page follows on from Create your first custom events: you'll find the page views you tracked, then read the fields of the product_viewed event and user entity.

Connect to your warehouse​

In Snowplow Console, open Destinations and select your warehouse or lake destination to see its connection details: the database or catalog, the schema, and the events table. Connect with your usual SQL client or the warehouse's own UI.

On Snowplow Self-Hosted, the connection details come from your Terraform variables instead. See connect to your warehouse for each warehouse.

Events usually take a few minutes to arrive after you track them. In the queries below, replace <events> with the full name of your events table.

Find your page views​

Every event has the same standard columns, such as event_name, app_id, collector_tstamp, and domain_userid. This query returns the most recent page views:

sql
SELECT
collector_tstamp,
app_id,
domain_userid,
page_urlpath
FROM <events>
WHERE event_name = 'page_view'
AND collector_tstamp > CURRENT_DATE - 1
ORDER BY collector_tstamp DESC
LIMIT 10

The filter on collector_tstamp matters: the events table is partitioned on it, so the filter keeps the query fast and cheap as your data grows. Atomic event fields describes every standard column.

If you don't see your events, check that they passed validation. Events that fail validation aren't loaded: you'll find them in Inspect your first failed events.

Query your custom event and entity​

Each custom event and entity gets its own column in the events table, named after its schema. For the product_viewed event with the vendor com.example_company, the column is unstruct_event_com_example_company_product_viewed_1. The user entity is in contexts_com_example_company_user_1, as an array, because an event can carry more than one entity of the same type.

sql
SELECT
collector_tstamp,
unstruct_event_com_example_company_product_viewed_1:productId::varchar AS product_id,
unstruct_event_com_example_company_product_viewed_1:price::number(10,2) AS price,
contexts_com_example_company_user_1[0]:userType::varchar AS user_type
FROM <events>
WHERE event_name = 'product_viewed'
AND collector_tstamp > CURRENT_DATE - 1

Fields are VARIANT values, so cast them to the type you need.

How schemas become columns explains the naming rules, including what happens when you publish a new schema version. For entities with several values, duplicate events, and Synapse Analytics, see Query Snowplow data in your warehouse.

Rather than writing every query against raw events, most teams run a data model next, which builds page view, session, and user tables from the events table.

Was this page helpful?