2

My tasks in snowflake are executing fine, I can run the below and get QueryID's for each instance that runs

SELECT * FROM TABLE(INFORMATION_SCHEMA.TASK_HISTORY(TASK_NAME=> 'TitanLoadSuccessVsFail')) 

But when I look at Query History for the warehouse that is running the tasks, there is none of these queryIDs.

SELECT * FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY_BY_WAREHOUSE(WAREHOUSE_NAME => 'ITSM_MWH'))
ORDER BY START_TIME DESC

How do I find

  1. The query history for the tasks that run
  2. The results from each queryID

Thanks nick

NRY
  • 51
  • 2

1 Answers1

3

This one is slightly tricky. INFORMATION_SCHEMA views for the most part only show you the results based on the role that you are currently querying them by. Tasks aren't actually executed by your role. They are considered system queries. If you look for them in the Snowflake UI, you will see them listed in History, but only if you check the box labeled Include queries executed by user tasks.

There are a bunch of options to get both the query history and the results from the query_id:

  1. Use the UI and check that box and include a date range to help you filter down the list to your tasks.
  2. Leverage the SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY view instead of INFORMATION_SCHEMA, which will require you to either be an ACCOUNTADMIN or have your ACCOUNTADMIN grant you the IMPORTED PRIVILEGES privilege to your role for the SNOWFLAKE database.
Mike Walton
  • 6,595
  • 2
  • 11
  • 22