This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Stored query results

1 - Stored query results

Learn how to manage stored query results.

Stored query results store the result of a query on the service for up to 24 hours. The same principal identity that created the stored query can reference the results in later queries.

Stored query results can be useful in the following scenarios:

  • Paging through query results. The initial command runs the query and returns the first “page” of records. Later queries reference other “pages” without the need to rerun the query.
  • Drill-down scenarios, in which the results of an initial query are then explored using other queries.

Updates to security policies, such as database access and row level security, aren’t propagated to stored query results. Use .drop stored_query_results if there’s user permission revocation.

Stored query results behave like tables, in that the order of records isn’t preserved. To paginate through the results, we recommended that the query includes unique ID columns. If a query returns multiple result sets, only the first result set is stored.

The following table lists the management commands and functions used for managing stored query results:

CommandDescription
.set stored_query_result commandCreates a stored query result to store the results of a query on the service for up to 24 hours.
.show stored_query_result commandShows information on active query results.
.drop stored_query_result commandDeletes active query results.
stored_query_result()Retrieves a stored query result.