Writing SQL
The dataset editor, schema-aware autocomplete, and what makes a good trend dataset.
In trend, a dataset is a saved SQL query — the unit of reuse across dashboards. Every chart binds to a dataset.
The editor
The dataset editor gives you schema-aware autocomplete. Type a table or column name and you’ll get completions from the schema cache for the connection you picked.
SELECT
date_trunc('week', created_at) AS week,
count(*) AS signups
FROM users
GROUP BY 1
ORDER BY 1
Click Preview to run against the connection. The result panel shows columns and rows; we cap previews at 10,000 rows by default.
Workspace vs. local datasets
- Workspace datasets live in the Datasets section. Any dashboard in the workspace can use them. Best for queries you’ll reuse — "Active users", "Daily revenue", "Top regions".
- Local datasets live inside a single dashboard. Best for one-off queries that don’t deserve to clutter the workspace library.
You can promote a local dataset to workspace-scope from its menu.
What makes a good dataset
- One unit of meaning per dataset. "Active users by week" is one. Don’t cram active users AND signups AND churn into one query just because they share a FROM clause.
- Templated parameters where appropriate. See Templates.
- Avoid heavy aggregations the chart could do. Return the raw grain when feasible — chart-level aggregations let one dataset feed multiple chart angles.
What to read next
- Templating with variables — the
{{var}}and[[clause]]syntax.