API Reference›Query
API Reference

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

POST/v1/query

Run 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

NameTypeDescription
X-Database-IdstringID of the database to query. Required unless you set the database_id body field.

Request body

NameTypeDescription
asyncbooleanRun 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_msintegerWith 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_idstringID 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_catalogstringCatalog that unqualified table names resolve to. Defaults to the database's default catalog; an unknown catalog fails with 400.
default_schemastringSchema 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".
dialectstringSQL dialect of sql: hotsql (default), duckdb, postgres, snowflake or clickhouse. Other dialects are translated to HotSQL before the query runs.
paramsobjectValues 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.

NameTypeDescription
columns (required)string[]Column names, in order.
execution_time_ms (required)integerTime 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)integerNumber of rows in this response.
query_run_id (required)stringID of the query run.
result_idstringID 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.
rollupRollupUsage
row_count (required)integerDeprecated: 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_countintegerNumber 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)booleanTrue when rows is only a preview of a larger result. Fetch the full result with result_id.
warningstringWhy 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.

NameTypeDescription
query_run_id (required)stringID of the query run.
reasonstringWhy the query went to the background, when known.
status (required)stringStatus of the query run. Always running here.
status_url (required)stringURL 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

StatusDescription
400Invalid request, such as no database given, or a header and body database_id that do not match.
403A write statement (INSERT, UPDATE, DELETE and so on) sent with a credential that lacks the read and write permissions
404Database not found
408The 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.
429Too many queries are running, or not enough memory is free. Retry after the Retry-After delay. If it continues, add a filter or LIMIT.
500Internal server error
503Temporarily unavailable, for example because the result could not be saved or the catalog is busy. Retry after the Retry-After delay.