Categories: Snowflake

Cool Stuff in Snowflake – Part 11: RESULT_SCAN

I’m doing a little series on some of the nice features/capabilities in Snowflake (the cloud data warehouse). In each part, I’ll highlight something that I think it’s interesting enough to share. It might be some SQL function that I’d really like to be in SQL Server, it might be something else.

This post builds upon part 6 of the series, which dealt with query history. There it is explained how Snowflake caches the query results. You can find a query in the history and take a look at what was returned. Using the RESULT_SCAN table function, you can do this with SQL. Let’s take a look at an example.

We first execute a query, retrieve the query ID from history and use that to get the result set:

If retrieving the query ID is too much work, or you would like a more automated solution, you can use the LAST_QUERY_ID function.

You can specify a positional parameter if you want to retrieve the query ID of a query which is not the last one. In the following example, we retrieve the result of the first query, instead of the last one:

There are many useful scenarios for RESULT_SCAN:

  • if you just ran a very long query and you forgot a part of the WHERE clause. Instead of re-running the (adapted) query, you just fetch the result set and filter that one. Much faster and ideal for debugging.
  • You can retrieve the output of a stored procedure.
  • You can also get the output of the SHOW and DESCRIBE commands.

Keep in mind though that Snowflake only keeps data in the result set cache for 24 hours. Starting from February 2020, it’s also possible you are billed if you query the result set cache too often. More information can be found here.


------------------------------------------------
Do you like this blog post? You can thank me by buying me a beer 🙂
Koen Verbeeck

Koen Verbeeck is a Microsoft Business Intelligence consultant at AE, helping clients to get insight in their data. Koen has a comprehensive knowledge of the SQL Server BI stack, with a particular love for Integration Services. He's also a speaker at various conferences.

Recent Posts

Power BI PBIR Format Admin Setting

The Power BI Enhanced Report Format (PBIR) will soon become the default, and that's a…

4 days ago

Logged in as a member of an Azure AD Group Error while Deploying DACPAC

Quite a long title for a short blog post :)While deploying a DACPAC (from a…

1 week ago

Export a Power BI Report that cannot be Downloaded

Yes, you're reading that right, we're going to download a report that cannot be downloaded.…

2 weeks ago

dataMinds Connect 2025 – Slides & Scripts

You can find all the session materials for the presentation "Indexing for Dummies" that was…

1 month ago

Cloud Data Driven User Group 2025 – Slides & Scripts

The slidedeck and the SQL scripts for the session Indexing for Dummies can be found…

2 months ago

Retro Data 2025 – Slidedeck

You can find the slides of my session on the €100 DWH in Azure on…

2 months ago