Query results and serialization
Query results are the shared record of query output between data source runners, background jobs, the web client, and API consumers. The system can reuse a recent result or run a query, stores successful output with its query identity and retrieval time, and presents the same data as JSON, CSV, TSV, or XLSX.
Result lifecycle
Result generation
The result flow turns a query request into either an existing result or a background job. A request may include parameter values and a maximum result age. The server checks access to the data source before it applies parameters and sends the query to the selected query runner. If no usable result exists, the response contains a job handle rather than waiting for the query to finish.
The background job records the runner output as a query result when execution succeeds. It links the new result to saved queries with the same query identity and data source. This link lets dashboards, alerts, and later requests use the newest output without running the query again.
flowchart LR
A[Query request] --> B{Usable cached result?}
B -- Yes --> C[Return result]
B -- No --> D[Queue query job]
D --> E[Run against data source]
E --> F{Execution succeeds?}
F -- No --> G[Return job failure]
F -- Yes --> H[Store query result]
H --> I[Update saved query links]
I --> J[Expose result to clients and workflows]
References: redash/…/query_results.py• L64-119 redash/…/execution.py• L197-263 redash/…/__init__.py• L347-383
Cached result retrieval
Caching is based on the data source and a hash of the effective query text. A request with max_age set to zero always runs the query. A positive value accepts only a result within that age. The default request can use an available result, with the configured expiry policy applied when enabled.
Saved queries point to their latest result. A client can request that latest result or request a result by its own ID. A result-specific response can be cached by the client for a long period because its content is immutable from the endpoint's point of view. A latest-result response does not receive that same long-lived cache header.
References: redash/…/__init__.py• L318-366 redash/…/query_results.py• L247-292 redash/…/query_results.py• L294-398 redash/…/api.py• L239-252
Query result reuse
The Query Results data source lets one query use output from other queries as temporary tables. A query can name a saved result, request a fresh result with parameters, or use a cached result explicitly. The system loads those inputs into the local query context before it evaluates the combining query.
This creates a bridge from stored result data to downstream query workflows. Access checks still apply to each referenced saved query, so result reuse does not bypass organization or data source permissions.
References: redash/…/query_results.py• L31-103 redash/…/query_results.py• L156-213 redash/…/test_query_results.py• L177-226
Result data model
Tabular result shape
Each result carries column metadata and row data. Columns provide names and types. Rows map those names to values. The result record also carries the query text, query hash, data source identity, run time, and retrieval time. This shape is the contract used by the client and by file exporters.
The result runner keeps column names unique and assigns a supported type when the source does not provide one. If values in one column do not share a type, the column falls back to a string type. This keeps mixed source data usable by views and exports.
References: redash/…/__init__.py• L311-338 redash/…/__init__.py• L39-47 redash/…/__init__.py• L215-229 redash/…/query_results.py• L183-213
Result retention
Stored results remain available while a saved query points to them or while a client can still retrieve them. A maintenance job removes older results that no saved query uses. The cleanup is bounded per run so result retention does not create a single large database operation.
References: redash/…/__init__.py• L340-345 redash/…/maintenance.py• L120-140
Client and API interfaces
Execution status
The API uses a job response for work that runs in the background. The job exposes a stable result ID after completion. The web client polls job status, then loads the result data through a separate request. It presents waiting, processing, loading, done, and failed states to the rest of the client.
The client also normalizes values for display. It recognizes dates and date-times, converts structured values to display text, and uses the server's column metadata when possible. A failed job or missing cached result becomes a client-visible error instead of an empty result.
References: redash/…/__init__.py• L293-336 redash/…/query_results.py• L422-428 client/…/query-result.js• L52-113 client/…/query-result.js• L137-195
Result retrieval API
The result API supports ad hoc execution, saved-query execution, latest-result retrieval, and result-by-ID retrieval. JSON responses carry the result object. File responses carry only the tabular output in CSV, TSV, or XLSX form. Query and data source access checks apply before result data is returned.
API users can use a query API key for permitted saved-query access. When an API user asks for a saved query's result, the server checks that the result belongs to the current query identity. This prevents a valid key from selecting an unrelated result.
References: redash/…/api.py• L228-253 redash/…/query_results.py• L147-192 redash/…/query_results.py• L224-398 redash/…/test_query_results.py• L198-330
Export formats
Exports preserve the result's column order and row values while adapting them to the target format. CSV and TSV use the organization date and time settings for typed date values. Booleans use the text values true and false. XLSX writes a worksheet named result and turns structured values into text so they can fit in a cell.
References: redash/…/query_result.py• L12-72 redash/…/query_result.py• L75-124 redash/…/query_results.py• L376-419 redash/…/test_query_results.py• L26-81
Downstream result workflows
Alert and saved-query updates
After a successful job stores a result, it updates every active saved query with the matching query hash and data source. The job then triggers alert checks for those saved queries. This ordering makes the new result visible before downstream alert logic evaluates it.
References: redash/…/execution.py• L243-263 redash/…/__init__.py• L756-795
Parameter and dropdown data
Parameterized queries use result data as input for later query execution. Query-backed dropdowns read values from a permitted query and expose them to a parent query or client. An associated dropdown query can be reached through the parent query's access, while an unrelated query requires its own access.
References: redash/…/query_results.py• L198-221 redash/…/parameterized_query.py• L1-35 tests/…/test_query_results.py• L333-404
For the wider query flow, see Querying and data sources. For the execution boundary between queries and data source runners, see Query runner platform. For the public HTTP surface, see Backend HTTP API.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the job status mapping aligned with the client status model. A change can make a completed job look like a failure or leave the client polling forever.
- Keep the result shape aligned across query runners,
QueryResult.to_dict(), JSON responses, and the client result adapter. Column names and types are shared by display, filtering, and export paths. - Keep query-hash inputs aligned between cache lookup, result storage, latest-result linking, and API-key result checks. A mismatch can return stale data or report a valid result as missing.
- Keep export type conversion aligned with organization date and time settings. Exported values are a client-facing contract and may differ from the raw JSON form.
- Keep permission checks in both result retrieval and Query Results data source reuse. Removing one path can expose data through a different result interface.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No cached result exists when a request asks for the latest result | The API returns a 404 and the client must run the query again | Treat a result ID as a completed execution artifact and handle the missing-cache response |
| A query hash differs between the saved query and the requested result | API-key access returns 404 even when the result exists | Build cache lookup and result validation from the same effective query text |
| A background job fails or is cancelled | No QueryResult is stored and the client receives a failed job state | Poll the job and surface its error before trying to load result data |
| A result column contains mixed value types | Views and exports may interpret values as strings | Preserve the result column metadata and use the string fallback for mixed values |
| A result is referenced after cleanup removes it | A dependent query or client receives no usable cached data | Keep saved-query links current and use fresh execution when the result is gone |
Key files
| File | Why to read it |
|---|---|
| redash/…/query_results.py | Defines the request paths for execution, cache selection, result retrieval, access checks, and file responses. |
| redash/…/__init__.py | Defines the stored result record, cache lookup rules, and links from saved queries to their latest result. |
| redash/…/execution.py | Shows how a completed job stores a result and starts alert checks after the result becomes current. |
| redash/…/query_results.py | Explains how stored results become inputs to a combining query. |
| redash/…/query_result.py | Defines JSON filtering and the CSV, TSV, and XLSX output forms. |
| redash/…/__init__.py | Defines the job response that connects background execution to a result ID. |
| client/…/query-result.js | Shows how the web client requests, polls, loads, interprets, and displays result data. |
| redash/…/api.py | Maps the result and job resources to their public API paths. |