TASK_HISTORY

functionsupportedUDFs, procedures, tasks, alerts, scripting

docs.snowflake.com ↗

Information SchemaTable functions

You can use this table function to query the history of task usage within a specified date range. The function returns the history of task usage for your entire Snowflake account, a specified task, or task graph. This function can return all executions run in the past seven days or the next scheduled execution within the next eight days.

Syntax

supportedpartialnot supportednot scored

TASK_HISTORY(
      [ SCHEDULED_TIME_RANGE_START => <constant_expr> ]
      [, SCHEDULED_TIME_RANGE_END => <constant_expr> ]
      [, RESULT_LIMIT => <integer> ]
      [, TASK_NAME => '<string>' ]
      [, DATABASE_NAME => '<string>' ]
      [, SCHEMA_NAME => '<string>' ]
      [, ERROR_ONLY => { TRUE | FALSE } ]
      [, ROOT_TASK_ID => '<string>' ]
      [, GRAPH_ID => '<string>' ]
      [, GRAPH_RUN_GROUP_ID => '<string>' ] )

Parameters

NameRequiredDescription
SCHEDULED_TIME_RANGE_START => constant_expr , SCHEDULED_TIME_RANGE_END => constant_exprrequiredTime range (in TIMESTAMP_LTZ format), within the last 7 days, in which the task execution was scheduled. If the time range does not fall within the last 7 days, an error is returned. If SCHEDULED_TIME_RANGE_END is not specified, the function returns those tasks that have already completed, are currently running, or are scheduled in the future. If SCHEDULED_TIME_RANGE_END is CURRENT_TIMESTAMP, the function returns those tasks that have already completed or are currently running. Note that a task that is executed immediately before the current time might still be identified as scheduled. To query only those tasks that have already completed or are currently running, include WHERE query_id IS NOT NULL as a filter. The QUERY_ID column in the TASK_HISTORY output is populated only when a task has started running. Note If no start or end time is specified, the most recent tasks are returned, up to the specified RESULT_LIMIT value.
RESULT_LIMIT => integerrequiredA number specifying the maximum number of rows returned by the function. If the number of matching rows is greater than this limit, the task executions with the most recent timestamp are returned, up to the specified limit. Range: 1 to 10000 Default: 100.
TASK_NAME => stringrequiredA case-insensitive string specifying a task. Only non-qualified task names are supported. Only executions of the specified task are returned. Note that if multiple tasks have the same name, the function returns the history for each of these tasks.
DATABASE_NAME => stringrequiredA string specifying which database to filter tasks by. Note that your role must have the USAGE privilege on the database. Use double quotes within the string to match case-sensitively.
SCHEMA_NAME => stringrequiredA string specifying which schema to filter tasks by. If you provide this argument, then you must also specify DATABASE_NAME. Note that your role must have the USAGE privilege on the schema and database. Use double quotes within the string to match case-sensitively.
ERROR_ONLY => { TRUE | FALSE }requiredWhen set to TRUE, this function returns only task runs that failed or were cancelled. Default: FALSE.
ROOT_TASK_ID =>stringrequiredUnique identifier for the root task in a root-task-based graph. This ID matches the ID column value in the SHOW TASKS output for the same task. Specify the ROOT_TASK_ID to show the history of the root task and any child tasks that are part of the graph. Mutually exclusive with GRAPH_ID.
GRAPH_ID =>stringrequiredUnique identifier for a task graph object. Specify the GRAPH_ID to show the history of all member tasks in the task graph. Mutually exclusive with ROOT_TASK_ID.
GRAPH_RUN_GROUP_ID => stringrequiredSpecifies a graph run group ID to return task runs for that group, including automatic retry attempts.

Usage notes

Output

The function returns the following columns: Column Name | Data Type | Description QUERY_ID | TEXT | ID of the SQL statement executed by the task. Can be joined with the QUERY_HISTORY view for additional details about the execution of the statement or stored procedure. NAME | TEXT | Name of the task. DATABASE_NAME | TEXT | Name of the database that contains the task. SCHEMA_NAME | TEXT | Name of the schema that contains the task. QUERY_TEXT | TEXT | Text of the SQL statement. CONDITION_TEXT | TEXT | Text of WHEN condition the task evaluates when determining whether to run. STATE | TEXT | Status of the task: SCHEDULED: scheduled for execution. EXECUTING: currently executing. SUCCEEDED: execution successful. FAILED: execution failed. The timed-out tasks always have a FAILED state in the task history. FAILED_AND_AUTO_SUSPENDED: task failed, and was automatically suspended. CANCELLED: execution cancelled. SKIPPED: indicates that a task run began, but the optional WHEN parameter in the task definition returned a FALSE value; therefore, the run did not resume the warehouse (if the task uses customer-managed compute resources) or execute the SQL code in the task definition. ERROR_CODE | NUMBER | Error code, if the statement returned an error. ERROR_MESSAGE | TEXT | Error message, if the statement returned an error. SCHEDULED_TIME | TIMESTAMP_LTZ | Time when the task is/was scheduled to start running. Tasks start with a brief queueing period before they begin to run. For more information, see Task duration. QUERY_START_TIME | TIMESTAMP_LTZ | Time when the query in the task definition started to run, or NULL if SCHEDULED_TIME is in the future or the current scheduled run has not started yet. This timestamp aligns with the start time for the query returned by QUERY_HISTORY. NEXT_SCHEDULED_TIME | TIMESTAMP_LTZ | Time when the standalone or root task (in a task graph) is next scheduled to start running, assuming the current run of the standalone task or task graph started at the SCHEDULED_TIME time completes in time. COMPLETED_TIME | TIMESTAMP_LTZ | Time when the task completed, or NULL if SCHEDULED_TIME is in the future or if the task is still running. ROOT_TASK_ID | TEXT | Unique identifier for the root task in a root-task-based graph. This ID matches the ID column value in the SHOW TASKS output for the same task. NULL for task graph objects. GRAPH_VERSION | NUMBER | Integer identifying the version of the task graph that was run, or is scheduled to be run. Each incremental increase in the value represents one or more modifications to tasks in the task graph. If the root task is recreated (using CREATE OR REPLACE TASK), then the version number restarts from 1. RUN_ID | NUMBER | Time when the standalone or root task in a task graph is/was originally scheduled to start running. Format is epoch time (in milliseconds). Original scheduled time refers to rare instances when the system might reschedule the same task to run at a different time to retry it or rebalance the load. If that happens, RUN_ID shows the original scheduled run time and SCHEDULED_TIME shows the rescheduled run time. Note that RUN_ID may not be a unique identifier for the current task/graph run before retry. You can use GRAPH_RUN_GROUP_ID column as a replacement for RUN_ID. RETURN_VALUE | TEXT | Value set for the predecessor task in a task graph. The return value is explicitly set by calling the System_Set_Return_Value function by the predecessor task. SCHEDULED_FROM | TEXT | One of: SCHEDULE: The task was scheduled to run normally, as described in SCHEDULE or AFTER clauses of CREATE TASK. EXECUTE_TASK: The task was scheduled to run with EXECUTE TASK. MANUAL RETRY: The task was scheduled to run with EXECUTE TASK … RETRY LAST. AUTOMATIC RETRY: The task was configured to retry on failure and the previous execution failed. For more information, see Automatically retry failed task runs. TRIGGER : The task was run because the stream, in the WHEN clause of the task, contained new data. For runs of child tasks in a task graph, the column returns the same value as the root task run. ATTEMPT_NUMBER | NUMBER | Integer representing the number of attempts to run this task. Initially one. CONFIG | TEXT | Configuration that the task execution used. This includes dynamic configurations specified with EXECUTE TASK … USING CONFIG. If no configuration is set, the column displays NULL. QUERY_HASH | TEXT | The hash value computed based on the canonicalized SQL text. QUERY_HASH_VERSION | NUMBER | The version of the logic used to compute QUERY_HASH. QUERY_PARAMETERIZED_HASH | TEXT | The hash value computed based on the parameterized query. QUERY_PARAMETERIZED_HASH_VERSION | NUMBER | The version of the logic used to compute QUERY_PARAMETERIZED_HASH. GRAPH_RUN_GROUP_ID | TEXT | Identifier for the graph run. When a graph run has multiple task runs, each task run will show the same GRAPH_RUN_GROUP_ID. The combination of GRAPH_RUN_GROUP_ID, and ATTEMPT_NUMBER can be used to uniquely identify a graph run. BACKFILL_INFO | OBJECT | Reserved for future use. The returned value for all rows is NULL. SPCS_JOB_ID | NUMBER | ID of the Snowpark Container Services (SPCS) job associated with this task run. NULL if the task did not run as a container job. GRAPH_ID | TEXT | Unique identifier for the task graph object. NULL for root-task-based graphs.