What it does
Run a data query: where, any (AND-ed with where when both are set), search (with snippets), similar_to, sort, paging, group_by, aggregates (per group, or one totals row without group_by), include, fields, meta, count_only, and visibility. where takes length_gt, length_gte, length_lt, length_lte and length_between on text columns; sort takes length(column). The SQL runs in Postgres. Sort keeps the first occurrence of each column and allows at most 5 distinct columns. On an own_and_shared table a member or site agent reads the shared rows plus its own private rows; visibility narrows that to shared or private.
Plans
Works on every plan: Free, Basic, Pro and Ultra.
Parameters
| Name | Type | About |
|---|---|---|
tablerequired | string | The table to query. |
where | object | Filters by column, all of which must match: a value, or one operator such as {"gte": 10}, {"contains": "x"}, {"empty": true} or {"length_gt": 30000} on a text column. |
any | array of objects | A list of where filters, of which at least one must match. |
search | string | Text to find in the table's searchable columns. |
snippets | boolean | With search: true adds _snippets (for each searchable text column that matched, a short excerpt with the matched words in **bold**) and _rank to every row. |
similar_to | string | Text to compare against, at most 500 characters: returns rows whose text is like it (trigram word similarity), most similar first unless you sort, each with _similarity from 0 to 1. |
similar_columns | array of string | Text columns similar_to compares, joined. Default: the table's searchable text columns. Short columns (a title, a summary) are faster and match better than long ones. |
similar_min | number | Lowest _similarity kept, from 0 to 1. Default 0.3. |
sort | string or array of string | A column to sort by, or length(column) for a text column's length; a leading - sorts descending. A list sorts by several columns. |
limit | number | How many rows to return per page. |
page | number | The page number, starting at 1. |
cursor | string | The next_cursor from the previous page, to continue. |
group_by | string | A column to group by. Returns one row per value with its count and the aggregates you ask for. Not with fields. |
sum | array of string | Columns to add up, per group, or without group_by in one totals row for the whole result. |
avg | array of string | Columns to average. |
min | array of string | Columns to return the smallest value of. |
max | array of string | Columns to return the largest value of. |
include | array of string | Relation columns whose linked rows to include in each row. |
fields | array of string | Column keys to return, such as ["slug","title"]. key:N returns the first N characters of a text column (rows it cut list it in _truncated); length(key) returns length_<key>, its length in characters. id, position, revision, created_at, updated_at, _member, _created_by and _updated_by always come back (only id and revision with meta min). Filters, search and sort can use other columns. Not with group_by or aggregates. It keeps long text columns out of the response. |
meta | one of: full, min | full (default) or min: each row carries only id and revision beside its values, with no position, times, _member, _created_by or _updated_by. |
count_only | boolean | true returns only total (the number of matching rows, or of groups with group_by), with no rows. |
visibility | one of: shared, private, all | Only for an own_and_shared table. shared: rows that belong to no member. private: your own private rows (the owner: every member's). all, the default: everything you may read, so the shared rows plus your own. |
site_id | string | Only for a site shared with you (whoami lists them): read or change that site's data as its member. |
Example
Call query_table with these arguments:
{
"table": "recipes",
"where": {
"vegetarian": true,
"minutes": {
"lte": 30
}
},
"sort": "minutes",
"limit": 20,
"fields": [
"title",
"minutes"
]
}
Ids like 01a1… stand for your own. list_sites and list_tables give you the real ones.
Related guides
- Search, filters and pagingLet visitors find rows in a long table.
- Show live data on a pageRows on the first paint, refreshed in the browser.
- Count, find and change many rowsYour agent answers questions about a table without reading every row.