SQL queries
Dashboard panels read your events with Cloudflare R2 SQL. This page documents the events table, the time filter, and the dialect.
The events table: $__table
At query time, $__table expands into a view already filtered to your data.
- Write
FROM $__table, optionally followed byWHERE/GROUP BY/ORDER BY/HAVING/LIMIT/OFFSET/JOIN…ON. - Do not alias it (no
$__table t); reference its columns unqualified.
The time filter
Include WHERE $__timeFilter(time) in Grafana panel queries so they only reads events within the dashboard’s selected time range.
Schema
| Column | Type | Non-nullable | Notes |
|---|---|---|---|
event |
string | ✅ | Event name |
time |
timestamp (ms) | ✅ | Event time |
distinct_id |
string | Identifies a unique installation of the app | |
properties |
string | JSON string of custom properties on the event | |
app_build_number |
string | App build number | |
app_version_string |
string | Mixpanel $app_version_string |
|
carrier |
string | Mixpanel $carrier |
|
city |
string | Mixpanel $city |
|
device_id |
string | Mixpanel $device_id |
|
had_persisted_distinct_id |
bool | Mixpanel $had_persisted_distinct_id |
|
lib_version |
string | Mixpanel $lib_version |
|
manufacturer |
string | Mixpanel $manufacturer |
|
model |
string | Mixpanel $model |
|
os |
string | Mixpanel $os |
|
os_version |
string | Mixpanel $os_version |
|
radio |
string | Mixpanel $radio |
|
region |
string | Mixpanel $region |
|
screen_height |
int64 | Mixpanel $screen_height |
|
screen_width |
int64 | Mixpanel $screen_width |
|
user_id |
string | Mixpanel $user_id |
|
wifi |
bool | Mixpanel $wifi |
|
mp_country_code |
string | Mixpanel mp_country_code |
|
mp_lib |
string | Mixpanel mp_lib |
|
mp_processing_time_ms |
int64 | Mixpanel mp_processing_time_ms |
|
mp_event_size |
int64 | Mixpanel $mp_event_size |
Other columns exist but are strictly metadata.
Dialect
- Use
SELECTstatements only. - Use
WITHto join and self-reference the events table. Do not useWITH RECURSIVE. - Reference only
$__table.SHOWandDESCRIBEare not currently supported.
See the R2 SQL reference for supported functions. JSON functions in particular are useful for reading any custom properties attached to your events.
Examples
Events per hour:
SELECT date_trunc('hour', time) AS hour, COUNT(*) AS event_count
FROM $__table
WHERE $__timeFilter(time)
GROUP BY date_trunc('hour', time)
ORDER BY date_trunc('hour', time)
Daily active users from app_launch events:
SELECT date_trunc('day', time) AS day, COUNT(DISTINCT distinct_id) AS dau
FROM $__table
WHERE event = 'app_launch' AND $__timeFilter(time)
GROUP BY date_trunc('day', time)
ORDER BY day