Contents Queries
Core resources / Queries
Run a query
Executes a query against a dataset and returns rows synchronously. Queries that exceed the synchronous limit return a job you poll instead — the same endpoint, a different shape, and the response tells you which one you got.
POST
/v3/datasets/{dataset_id}/queries
import { Quarry } from '@quarry/node' const quarry = new Quarry(process.env.QUARRY_KEY) // Rows come back synchronously under ~15s of compute. const result = await quarry.queries.run('ds_8c14', { select: ['region', 'sum(revenue) as revenue'], where: { closed_at: { gte: '2026-01-01' } }, group: ['region'], limit: 500, }) if (result.status === 'pending') { // Too large for a synchronous answer. Poll the job. await quarry.jobs.wait(result.job_id) }
import os from quarry import Quarry quarry = Quarry(os.environ["QUARRY_KEY"]) # Rows come back synchronously under ~15s of compute. result = quarry.queries.run( "ds_8c14", select=["region", "sum(revenue) as revenue"], where={"closed_at": {"gte": "2026-01-01"}}, group=["region"], limit=500, ) if result.status == "pending": quarry.jobs.wait(result.job_id)
curl https://api.quarry.dev/v3/datasets/ds_8c14/queries \ -H "Authorization: Bearer $QUARRY_KEY" \ -H "Content-Type: application/json" \ -d '{ "select": ["region", "sum(revenue) as revenue"], "where": { "closed_at": { "gte": "2026-01-01" } }, "group": ["region"], "limit": 500 }'
Parameters
| Field | Type | Description |
|---|---|---|
| select | string[] Required |
Columns or aggregate expressions to return. Aliases with as are supported and become the key in each row. |
| where | object Optional |
Filter tree. Operators are eq, ne, gt, gte, lt, lte, in and contains. |
| group | string[] Optional |
Grouping columns. Every non-aggregate entry in select must appear here, or the request is rejected with 422. |
| limit | integer Optional |
Maximum rows returned. Defaults to 1000, capped at 50000. Larger results should use an export. |
| cursor | string Optional |
Opaque cursor from a previous response's next_cursor. Cursors expire after one hour. |
Why some queries come back pending
Anything projected to exceed fifteen seconds of compute is promoted to a job rather than held open on the connection. You cannot force the synchronous path — but you can make it more likely by narrowing the date range or raising the grouping level.
Response
A successful synchronous response carries status: "complete" and a rows array. A promoted query carries status: "pending" and a job_id, with no rows at all — check status before reading rows, not the other way round.
{
"status": "complete",
"row_count": 4,
"next_cursor": null,
"elapsed_ms": 318,
"rows": [
{ "region": "emea", "revenue": 4182900 },
{ "region": "amer", "revenue": 6640155 },
{ "region": "apac", "revenue": 2091044 },
{ "region": "latam", "revenue": 877310 }
]
}
Errors
Every error carries a machine-readable code and a message written for a human reading a log at two in the morning. The message is safe to show to your own users; the detail field is not, because it can echo query fragments.
| Status | Code | What went wrong |
|---|---|---|
| 401 | invalid_key | The key is malformed, revoked, or belongs to a different environment. |
| 422 | ungrouped_column | A non-aggregate column in select is missing from group. |
| 429 | rate_limited | Over the concurrency limit. Retry-After is always present on this response. |
| 503 | dataset_rebuilding | The dataset is mid-rebuild. Reads resume automatically; this is never longer than ten minutes. |