Query
Run SQL queries against a database. Rows come back inline, and the result is also saved so you can read it again from the Results API.
Execute SQL query
/v1/queryRun a SQL query against one database. Choose the database with the X-Database-Id header or the database_id body field; if you send both, they must match. The query sees the database's default catalog and any catalogs attached to it, by their alias. Rows come back inline, with a result_id for reading the result again from the Results API.
Async. Set async: true to get a query run ID back at once and poll for the result. Add async_after_ms (1000 to 30000) to wait that long for an inline result first.
Arrow. Send Accept: application/vnd.apache.arrow.stream (without application/json) to get the rows as an Arrow IPC stream. The values the JSON body would carry come as X-Query-Run-Id, X-Result-Id, X-Total-Row-Count, X-Execution-Time-Ms, X-Query-Warning and X-Rollup headers. If the result is too large to send inline, you get a 202 with an X-Result-Id header; read the full result from GET /v1/results/{id}?format=arrow. Async runs and errors still return JSON.
Writes. INSERT, UPDATE, DELETE, CREATE TABLE, CREATE TABLE … AS SELECT and DROP TABLE are supported. A write needs an API key with both the read and write permissions, can only change the database's default catalog, and returns one row with a rows_affected column. INSERT only appends. UPDATE and DELETE do not support RETURNING, LIMIT or ORDER BY. UPDATE also refuses table aliases, FROM, and setting a vector-index column, or a key or constant_per_key column. Other changes (ALTER, views, COPY, transactions) are refused.
Headers
| Name | Type | Description |
|---|---|---|
X-Database-Id | string | ID of the database to query. Required unless you set the database_id body field. |
Request body
| Name | Type | Description |
|---|---|---|
async | boolean | Run the query in the background and return a query run ID right away. Poll GET /v1/query-runs/{id} for its status. Default: false |
async_after_ms | integer | With async: true, wait up to this many milliseconds for the result before falling back to a query run ID. Must be between 1000 and 30000. Min: 1000 |
database_id | string | ID of the database to query. Use this or the X-Database-Id header; if both are set they must match, or the request fails with 400. |
default_catalog | string | Catalog that unqualified table names resolve to. Defaults to the database's default catalog; an unknown catalog fails with 400. |
default_schema | string | Schema that unqualified table names resolve to. Defaults to the database's default_schema; a schema that does not exist makes unqualified tables fail with "table not found". |
dialect | string | SQL dialect of sql: hotsql (default), duckdb, postgres, snowflake or clickhouse. Other dialects are translated to HotSQL before the query runs. |
params | object | Values for the parameters sql names as $name, by name. A value is bound as a value, never as SQL text, so it cannot change what the statement does. Works in reads and in INSERT, UPDATE and DELETE. Every $name in the SQL needs a value and every value must be used, or the request fails with 400. Each value takes the type the SQL gives its parameter: ts >= $start reads start as a timestamp string, id = $id as the type of id, and a value that does not fit that type is refused. Where the SQL gives the parameter no type (SELECT $x), a string, number or boolean keeps its own type; write CAST($x AS ...) to choose another, and a null needs a typed position. Parameters are not available in other dialects, and cannot be arguments of vector_search, bm25_search or the vector distance functions. |
sql (required) | string |
Example request
{
"async": false,
"database_id": "dbid6lguax1dxn9y1xj5gxnameyywl",
"default_catalog": "default",
"default_schema": "public",
"dialect": "hotsql",
"sql": "SELECT customer_id, sum(amount) AS total FROM orders GROUP BY customer_id ORDER BY total DESC LIMIT 10"
}
Response 200 — The query ran. JSON by default, or an Arrow IPC stream if you asked for one.
| Name | Type | Description |
|---|---|---|
columns (required) | string[] | Column names, in order. |
execution_time_ms (required) | integer | Time the query took to run, in milliseconds. |
nullable (required) | boolean[] | Whether each column, in the same order as columns, can hold nulls. |
preview_row_count (required) | integer | Number of rows in this response. |
query_run_id (required) | string | ID of the query run. |
result_id | string | ID to fetch this result again with GET /v1/results/{id}. Null only when every row is in this response but the result could not be saved; see warning. |
rollup | RollupUsage | |
row_count (required) | integer | Deprecated: use preview_row_count or total_row_count. Always equal to preview_row_count. |
rows (required) | any[][] | Result rows. Each row is an array of values in column order. |
total_row_count | integer | Number of rows in the full result. Null while a truncated result is still being saved; read row_count from the query run once it succeeds. |
truncated (required) | boolean | True when rows is only a preview of a larger result. Fetch the full result with result_id. |
warning | string | Why the result could not be saved. Present only when result_id is null; every row is still in this response. |
Example response
{
"columns": [
"string"
],
"execution_time_ms": 0,
"nullable": [
true
],
"preview_row_count": 0,
"query_run_id": "string",
"result_id": "string",
"rollup": "used",
"row_count": 0,
"rows": [
[
null
]
],
"total_row_count": 0,
"truncated": true,
"warning": "string"
}
Response 202 — The query is running in the background. For an Arrow request, this also means the result was too large to send inline.
| Name | Type | Description |
|---|---|---|
query_run_id (required) | string | ID of the query run. |
reason | string | Why the query went to the background, when known. |
status (required) | string | Status of the query run. Always running here. |
status_url (required) | string | URL to poll for the run's status. Send the same X-Database-Id header. |
Example response
{
"query_run_id": "string",
"reason": "string",
"status": "string",
"status_url": "string"
}
Errors
| Status | Description |
|---|---|
400 | Invalid request, such as no database given, or a header and body database_id that do not match. |
403 | A write statement (INSERT, UPDATE, DELETE and so on) sent with a credential that lacks the read and write permissions |
404 | Database not found |
408 | The query ran past the time limit and was stopped. A query this slow is likely to time out again: narrow it, for example with a filter, or read from a rollup or an index. |
429 | Too many queries are running, or not enough memory is free. Retry after the Retry-After delay. If it continues, add a filter or LIMIT. |
500 | Internal server error |
503 | Temporarily unavailable, for example because the result could not be saved or the catalog is busy. Retry after the Retry-After delay. |