Skip to content

docs(zql): document aggregates - #328

Open
arv wants to merge 3 commits into
mainfrom
arv/aggregates
Open

arv wants to merge 3 commits into
mainfrom
arv/aggregates

Conversation

@arv

@arv arv commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Adds an Aggregates section to the ZQL page covering count(), sum(), avg(), min(), and max() on queries and relationships:

  • A top-level aggregate returns a single value. On a relationship, each row gets the value in place of the related rows.
  • Only the result is synced, and it stays up to date as rows change.
  • where(), start(), and limit() apply before the aggregate, as in SQL.
  • Column types, empty results (0 for count(), null otherwise), and which aggregates update immediately when a mutator runs.

It also adds Distinct and Group By subsections, for distinct() and groupBy(...).count()/sum()/avg()/min()/max(), which depend on rocicorp/mono-internal#295 and rocicorp/mono-internal#296:

  • distinct() returns one row per combination of its columns, and distinct().count() counts them, with null counted as a value, unlike SQL's COUNT(DISTINCT).
  • groupBy() returns one row per group with the aggregate under the function's name. null forms a group, and rows are ordered by the grouped columns only.
  • What they don't support yet: limit(), start(), one(), related(), a further aggregate, use in related()/whereExists(), JSON group columns, and ordering by the aggregate.
  • Which ones update immediately when a mutator runs.

Also regenerates assets/search-index.json.

Draft until aggregates, and #295/#296 for the new subsections, ship in a Zero release. The roadmap and status pages still list aggregates and group-by as future work and should be updated then.

@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
zero-docs Ready Ready Preview Oct 30, 2026 6:19pm UTC

Request Review

@arv
arv requested a lite review from Copilot October 27, 2026 11:17
@arv
arv requested a review from aboodman October 27, 2026 11:17
@arv
arv marked this pull request as ready for review October 27, 2026 11:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The remaining feedback is limited to non-blocking wording nits.

No open issues 🎉

What changed in this PR

Documents ZQL aggregate queries and regenerates the search index for the new documentation section.

Changes:

  • Adds documentation for count(), sum(), avg(), min(), and max().
  • Covers relationship aggregates, filtering, pagination, result types, synchronization, and mutation updates.
  • Regenerates search-index entries and heading identifiers.
File Summary
contents/​docs/​zql.mdx Adds the Aggregates section with usage examples and behavioral details.
assets/​search-index.json Indexes the new section and updates subsequent section identifiers.

Review effort: Lite

This branch was successfully deployed

1 active deployment
Preview — e9d1c2bd Deployed Oct 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants