RESULT_SCAN

functionsupportedQueries & DML

docs.snowflake.com ↗

Table functions

Returns the result set of a previous command (within 24 hours of when you ran the query) as if the result was a table. This function is particularly useful if you want to process the output from any of the following operations: - SHOW or DESC[RIBE] command that you ran. - Query that you ran on metadata or account usage information, such as Snowflake Information Schema or Account Usage. - The result of a stored procedure that you called. As an alternative to using RESULT_SCAN, you can call a stored procedure that returns tabular data in the FROM clause of a SELECT statement. The command or query can be from the current session or any of your other sessions, including past sessions, as long as the 24 hour period hasn’t elapsed. This period isn’t adjustable. For more information, see Using Persisted Query Results. Tip You can use the pipe operator (->>) instead of this function to process the results of a previous command.

Syntax

supportedpartialnot supportednot scored

RESULT_SCAN ( [ { '<query_id>' | <query_index>  | LAST_QUERY_ID() } ] )

Parameters

NameRequiredDescription
'query_id' or query_index or LAST_QUERY_ID()requiredA specification of a query that you ran within the last 24 hours in any session, an integer index of a query in the current session, or the LAST_QUERY_ID function, which returns the ID of a query within your current session. Snowflake query IDs are unique strings that resemble 01b71944-0001-b181-0000-0129032279f6. Query indexes are relative to the first query in the current session (if positive) or to the most recent query (if negative). For example, RESULT_SCAN(-1) is equivalent to RESULT_SCAN(LAST_QUERY_ID()). This argument is optional. If it is omitted, the default is RESULT_SCAN(-1), which returns the result set of the most recent command.

Usage notes

Collation details

When RESULT_SCAN returns the results of the previous statement, RESULT_SCAN preserves the collation specification(s) of the values that it returns.

See also

Referenced by