API Reference›Saved Queries
API Reference

Saved Queries

Save, version and run named SQL queries. Changing a query's SQL creates a new version and keeps the old ones.

List saved queries

GET/v1/queries

List saved queries, sorted by name.

Query parameters

NameTypeDescription
limitintegerSaved queries to return. Default 100, maximum 1000.
offsetintegerNumber of saved queries to skip. Default 0.

Response 200 — List of saved queries

NameTypeDescription
count (required)integer
has_more (required)boolean
limit (required)integer
offset (required)integer
queries (required)SavedQuerySummary[]
Fields of queries
NameTypeDescription
queries[].created_at (required)string
queries[].description (required)string
queries[].id (required)string
queries[].latest_version (required)integer
queries[].name (required)string
queries[].tags (required)string[]
queries[].updated_at (required)string
Example response
{
  "count": 0,
  "has_more": true,
  "limit": 0,
  "offset": 0,
  "queries": [
    {
      "created_at": "2026-01-01T00:00:00Z",
      "description": "string",
      "id": "string",
      "latest_version": 0,
      "name": "string",
      "tags": [
        "string"
      ],
      "updated_at": "2026-01-01T00:00:00Z"
    }
  ]
}

Create saved query

POST/v1/queries

Save a named SQL query as version 1. Hotdata classifies the SQL, for example its category, table count, and whether it filters, joins or aggregates.

Request body

NameTypeDescription
descriptionstring
name (required)string
paramsQueryParam[]Parameters the SQL uses, written in it as $name. Each value is checked against its type and bound as a value when the query runs, never as SQL text. Every $name in the SQL must be declared here, and every declared parameter must appear in the SQL.
sql (required)string
tagsstring[]
Fields of params
NameTypeDescription
params[].defaultobjectValue used when an execution does not supply one. Without a default, every execution must supply the parameter. null is a valid default.
params[].descriptionstringWhat the parameter is for.
params[].name (required)stringName used in the SQL after $. Letters, digits and underscores, starting with a letter or underscore.
params[].type (required)stringType of the value: string, int, float, bool, timestamp, date or interval.
Example request
{
  "description": "Ten highest-spending customers by order total",
  "name": "top-customers",
  "params": [
    {
      "name": "start",
      "type": "timestamp"
    },
    {
      "name": "bucket",
      "type": "interval",
      "default": "1 hour"
    }
  ],
  "sql": "SELECT customer_id, sum(amount) AS total FROM orders GROUP BY customer_id ORDER BY total DESC LIMIT 10",
  "tags": [
    "sales",
    "weekly"
  ]
}

Response 201 — Saved query created

NameTypeDescription
categorystring
created_at (required)string
description (required)string
has_aggregationboolean
has_group_byboolean
has_joinboolean
has_limitboolean
has_order_byboolean
has_predicateboolean
id (required)string
latest_version (required)integer
name (required)string
num_tablesinteger
params (required)QueryParam[]Parameters the latest version declares.
sql (required)string
sql_hash (required)string
table_sizestring
tags (required)string[]
updated_at (required)string
Fields of params
NameTypeDescription
params[].defaultobjectValue used when an execution does not supply one. Without a default, every execution must supply the parameter. null is a valid default.
params[].descriptionstringWhat the parameter is for.
params[].name (required)stringName used in the SQL after $. Letters, digits and underscores, starting with a letter or underscore.
params[].type (required)stringType of the value: string, int, float, bool, timestamp, date or interval.
Example response
{
  "category": "string",
  "created_at": "2026-01-01T00:00:00Z",
  "description": "string",
  "has_aggregation": true,
  "has_group_by": true,
  "has_join": true,
  "has_limit": true,
  "has_order_by": true,
  "has_predicate": true,
  "id": "string",
  "latest_version": 0,
  "name": "string",
  "num_tables": 0,
  "params": [
    {
      "default": {},
      "description": "string",
      "name": "window_start",
      "type": "timestamp"
    }
  ],
  "sql": "string",
  "sql_hash": "string",
  "table_size": "string",
  "tags": [
    "string"
  ],
  "updated_at": "2026-01-01T00:00:00Z"
}

Errors

StatusDescription
400Invalid request

Get saved query

GET/v1/queries/{id}

Get a saved query and its latest version.

Path parameters

NameTypeDescription
id (required)stringSaved query ID

Response 200 — Saved query details

NameTypeDescription
categorystring
created_at (required)string
description (required)string
has_aggregationboolean
has_group_byboolean
has_joinboolean
has_limitboolean
has_order_byboolean
has_predicateboolean
id (required)string
latest_version (required)integer
name (required)string
num_tablesinteger
params (required)QueryParam[]Parameters the latest version declares.
sql (required)string
sql_hash (required)string
table_sizestring
tags (required)string[]
updated_at (required)string
Fields of params
NameTypeDescription
params[].defaultobjectValue used when an execution does not supply one. Without a default, every execution must supply the parameter. null is a valid default.
params[].descriptionstringWhat the parameter is for.
params[].name (required)stringName used in the SQL after $. Letters, digits and underscores, starting with a letter or underscore.
params[].type (required)stringType of the value: string, int, float, bool, timestamp, date or interval.
Example response
{
  "category": "string",
  "created_at": "2026-01-01T00:00:00Z",
  "description": "string",
  "has_aggregation": true,
  "has_group_by": true,
  "has_join": true,
  "has_limit": true,
  "has_order_by": true,
  "has_predicate": true,
  "id": "string",
  "latest_version": 0,
  "name": "string",
  "num_tables": 0,
  "params": [
    {
      "default": {},
      "description": "string",
      "name": "window_start",
      "type": "timestamp"
    }
  ],
  "sql": "string",
  "sql_hash": "string",
  "table_size": "string",
  "tags": [
    "string"
  ],
  "updated_at": "2026-01-01T00:00:00Z"
}

Errors

StatusDescription
404Saved query not found

Update saved query

PUT/v1/queries/{id}

Update a saved query. Send at least one field; fields you omit do not change. Changing the SQL creates a new version and keeps the old ones.

Path parameters

NameTypeDescription
id (required)stringSaved query ID

Request body

NameTypeDescription
category_overridestringCategory to use instead of the detected one, such as point_lookup or join. Send null to go back to the detected category.
descriptionstringNew description. Omit to keep the current one.
namestringNew name. Omit to keep the current one.
paramsQueryParam[]New parameters, replacing the current ones; send [] to remove them. Omit to keep them. Changing the parameters creates a new version, as changing the SQL does.
sqlstringNew SQL. Omit to keep the current SQL.
table_size_overridestringYour own label for the table size. Send null to clear it.
tagsstring[]New tags, replacing the current ones. Omit to keep them.
Fields of params
NameTypeDescription
params[].defaultobjectValue used when an execution does not supply one. Without a default, every execution must supply the parameter. null is a valid default.
params[].descriptionstringWhat the parameter is for.
params[].name (required)stringName used in the SQL after $. Letters, digits and underscores, starting with a letter or underscore.
params[].type (required)stringType of the value: string, int, float, bool, timestamp, date or interval.
Example request
{
  "params": [
    {
      "name": "window_start",
      "type": "timestamp"
    }
  ]
}

Response 200 — Saved query updated

NameTypeDescription
categorystring
created_at (required)string
description (required)string
has_aggregationboolean
has_group_byboolean
has_joinboolean
has_limitboolean
has_order_byboolean
has_predicateboolean
id (required)string
latest_version (required)integer
name (required)string
num_tablesinteger
params (required)QueryParam[]Parameters the latest version declares.
sql (required)string
sql_hash (required)string
table_sizestring
tags (required)string[]
updated_at (required)string
Fields of params
NameTypeDescription
params[].defaultobjectValue used when an execution does not supply one. Without a default, every execution must supply the parameter. null is a valid default.
params[].descriptionstringWhat the parameter is for.
params[].name (required)stringName used in the SQL after $. Letters, digits and underscores, starting with a letter or underscore.
params[].type (required)stringType of the value: string, int, float, bool, timestamp, date or interval.
Example response
{
  "category": "string",
  "created_at": "2026-01-01T00:00:00Z",
  "description": "string",
  "has_aggregation": true,
  "has_group_by": true,
  "has_join": true,
  "has_limit": true,
  "has_order_by": true,
  "has_predicate": true,
  "id": "string",
  "latest_version": 0,
  "name": "string",
  "num_tables": 0,
  "params": [
    {
      "default": {},
      "description": "string",
      "name": "window_start",
      "type": "timestamp"
    }
  ],
  "sql": "string",
  "sql_hash": "string",
  "table_size": "string",
  "tags": [
    "string"
  ],
  "updated_at": "2026-01-01T00:00:00Z"
}

Errors

StatusDescription
400Invalid request
404Saved query not found

Delete saved query

DELETE/v1/queries/{id}

Delete a saved query and all its versions.

Path parameters

NameTypeDescription
id (required)stringSaved query ID

Response 204 — Saved query deleted

Errors

StatusDescription
404Saved query not found

Execute saved query

POST/v1/queries/{id}/execute

Run a saved query in the database named by the X-Database-Id header. Runs the latest version unless you pass version. Returns the same response as POST /v1/query. Write statements are refused.

Path parameters

NameTypeDescription
id (required)stringSaved query ID

Headers

NameTypeDescription
X-Database-Id (required)stringID of the database to run the query in. Required.

Request body

NameTypeDescription
paramsobjectA value for each parameter the version declares, by name. A parameter you leave out takes its default. null passes a null of the parameter's type.
versionintegerVersion to run. Defaults to the latest.

All fields are optional. Send only the ones you want to set.

Response 200 — Query executed

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"
}

Errors

StatusDescription
400Invalid request, such as a missing X-Database-Id header
404Saved query or database 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.

List saved query versions

GET/v1/queries/{id}/versions

List the versions of a saved query, newest first.

Path parameters

NameTypeDescription
id (required)stringSaved query ID

Query parameters

NameTypeDescription
limitintegerVersions to return. Default 100, maximum 1000.
offsetintegerNumber of versions to skip. Default 0.

Response 200 — List of versions

NameTypeDescription
count (required)integer
has_more (required)boolean
limit (required)integer
offset (required)integer
saved_query_id (required)string
versions (required)SavedQueryVersionInfo[]
Fields of versions
NameTypeDescription
versions[].categorystring
versions[].created_at (required)string
versions[].has_aggregationboolean
versions[].has_group_byboolean
versions[].has_joinboolean
versions[].has_limitboolean
versions[].has_order_byboolean
versions[].has_predicateboolean
versions[].num_tablesinteger
versions[].params (required)QueryParam[]Parameters this version declares.
versions[].params[].defaultobjectValue used when an execution does not supply one. Without a default, every execution must supply the parameter. null is a valid default.
versions[].params[].descriptionstringWhat the parameter is for.
versions[].params[].name (required)stringName used in the SQL after $. Letters, digits and underscores, starting with a letter or underscore.
versions[].params[].type (required)stringType of the value: string, int, float, bool, timestamp, date or interval.
versions[].sql (required)string
versions[].sql_hash (required)string
versions[].table_sizestring
versions[].version (required)integer
Example response
{
  "count": 0,
  "has_more": true,
  "limit": 0,
  "offset": 0,
  "saved_query_id": "string",
  "versions": [
    {
      "category": "string",
      "created_at": "2026-01-01T00:00:00Z",
      "has_aggregation": true,
      "has_group_by": true,
      "has_join": true,
      "has_limit": true,
      "has_order_by": true,
      "has_predicate": true,
      "num_tables": 0,
      "params": [
        {}
      ],
      "sql": "string",
      "sql_hash": "string",
      "table_size": "string",
      "version": 0
    }
  ]
}

Errors

StatusDescription
404Saved query not found