Summarize Table Data
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name/summarize
This endpoint summarizes from your database. It comes with a range of functions to help perform calculations on the data you have stored in your tables
Expected parameters
Name | Description | In | Required | Schema |
---|---|---|---|---|
db_branch_name | The DBBranchName matches the pattern `{db_name}:{branch_name}`. | path | ✅ | string |
table_name | The Table name | path | ✅ | string |
Summarize Table
POSThttps://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name/summarize
This endpoint allows you to (optionally) define groups, and then to run calculations on the values in each group. This is most helpful when you'd like to understand the data you have in your database.
A group is a combination of unique values. If you create a group for
sold_by
, product_name
, we will return one row for every combination
of sold_by
and product_name
you have in your database. When you
want to calculate statistics, you define these groups and ask Xata to
calculate data on each group.
Some questions you can ask of your data:
How many records do I have in this table?
- Set
columns: []
as we we want data from the entire table, so we ask for no groups. - Set
summaries: {"total": {"count": "*"}}
in order to see the count of all records. We usecount: *
here we'd like to know the total amount of rows; ignoring whether they arenull
or not.
What are the top total sales for each product in July 2022 and sold more than 10 units?
- Set
filter: {soldAt: { "$ge": "2022-07-01T00:00:00.000Z", "$lt": "2022-08-01T00:00:00.000Z"} }
in order to limit the result set to sales recorded in July 2022. - Set
columns: [product_name]
as we'd like to run calculations on each unique product name in our table. Settingcolumns
like this will produce one row per unique product name. - Set
summaries: {"total_sales": {"count": "product_name"}}
as we'd like to create a field called "total_sales" for each group. This field will count all rows in each group with non-null product names. - Set
sort: [{"total_sales": "desc"}]
in order to bring the rows with the highest total_sales field to the top. - Set
summariesFilter: {"total_sales": {"$ge": 10}}
to only send back data with greater than or equal to 10 units.
columns
: tells Xata how to create each group. If you add product_id
we will create a new group for every unique product_id
.
summaries
: tells Xata which calculations to run on each group. Xata
currently supports count, min, max, sum, average.
sort
: tells Xata in which order you'd like to see results. You may
sort by fields specified in columns
as well as the summary names
defined in summaries
.
note: Sorting on summarized values can be slower on very large tables;
this will impact your rate limit significantly more than other queries.
Try use filter
to reduce the amount of data being processed in order
to reduce impact on your limits.
summariesFilter
: tells Xata how to filter the results of a summary.
It has the same syntax as filter
, however, by using summariesFilter
you may also filter on the results of a query.
note: This is a much slower to use than filter
. We recommend using
filter
wherever possible and summariesFilter
when it's not
possible to use filter
.
page.size
: tells Xata how many records to return. If unspecified, Xata
will return the default size.