result_scan

Applies to: ✅ Data 360 SQL

Returns the result set of a completed query as a table. Use result_scan in the FROM clause to query cached results without rerunning the original query.

  • <query_id>: The query identifier returned by the Data 360 Query API when the source query was submitted. Pass it as a string literal. You can’t use a column reference or a computed expression.

Returns a set of rows whose column names and data types match the result set of the referenced query. Use it anywhere a table reference is valid in a FROM clause.

result_scan is a set-returning function that must appear in the FROM clause, not in a SELECT list or WHERE clause.

  • The referenced query must complete successfully and produce a result set before you can call result_scan against it. Queries that are still running, have failed, don’t exist, or return no rows result in an error.
  • When you submit a query using the Data 360 Query API, store the returned queryId and pass it to subsequent result_scan calls. A single query can contain multiple calls referencing the same or different IDs.
  • Rows returned by result_scan might not match the order of the original query. Use an explicit ORDER BY clause if sorting matters.
  • Data 360 retains query results for up to 24 hours, though they may become unavailable sooner due to cache eviction. If results expire or are evicted, resubmit the original query to regenerate the result set.
  • You can only scan results from queries that you submitted within your current data space. Referencing a query issued by another user or running in a different data space returns an error.
SQLSTATEConditionMessage
42704Query ID not found, not yours, not finished, or expiredThe result of the query '<queryId>' cannot be scanned. Either the query id does not exist, the query was issued by another user, the query execution has not finished yet or the result expired.
42704Query still runningThe result of the query '<queryId>' cannot be scanned. The query execution has not finished yet.
22023Source query produced no result setThe query '<queryId>' did not produce a result.

Because result_scan returns the schema of the source query, expected output depends on your data. The examples below show query structure only.

Submit an initial query and store the returned queryId. Use result_scan to aggregate the cached results without rerunning the source query. Pass the queryId value (for example, '3442db1a-ecef-42b3-b0d8-971ee459efa4') returned by the Data 360 Query API.

Filter results from a completed query without rescanning the source table.

Reference two different cached result sets in a single query.