Schema:

ACCOUNT_USAGE

TASK_HISTORY view¶

This Account Usage view enables you to retrieve the history of task usage within the last 365 days (1 year). The view displays one row for each run of a task in the history.

Columns¶

Column Name

Data Type

Description

NAME

TEXT

Name of 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.

SCHEMA_NAME

TEXT

Name of the schema that contains the task.

TASK_SCHEMA_ID

NUMBER

Internal/system-generated identifier for the schema that contains the task.

DATABASE_NAME

TEXT

Name of the database that contains the task.

TASK_DATABASE_ID

NUMBER

Internal/system-generated identifier for the database that contains the task.

SCHEDULED_TIME

TIMESTAMP_LTZ

Time when the task is/was scheduled to start running. Note that we make a best effort to ensure absolute precision, but only guarantee that tasks do not execute before the scheduled time.

COMPLETED_TIME

TIMESTAMP_LTZ

Time when the task completed.

STATE

TEXT

Status of the completed task: SUCCEEDED, FAILED, CANCELLED, or SKIPPED. Note that the view does not return SCHEDULED or EXECUTING task runs. To retrieve the task history details for runs in a scheduled or executing state, query the TASK_HISTORY table function in the Information Schema. The timed-out tasks always have a FAILED state in the task history.

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.

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.

QUERY_START_TIME

TIMESTAMP_LTZ

Time when the query in the task definition started to run. This timestamp aligns with the start time for the query returned by QUERY_HISTORY.

ERROR_CODE

NUMBER

Error code, if the statement returned an error.

ERROR_MESSAGE

TEXT

Error message, if the statement returned an error.

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 may 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 prior to retry. You may use GRAPH_RUN_GROUP_ID column as a replacement for RUN_ID.

ROOT_TASK_ID

TEXT

Unique identifier for the root task in a task graph. This ID matches the ID column value in the SHOW TASKS output for the same 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 using EXECUTE TASK.

  • MANUAL RETRY: The task was scheduled to run using EXECUTE TASK … RETRY LAST.

  • 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.

INSTANCE_ID

NUMBER

Internal/system-generated identifier for the instance which the object belongs to.

CONFIG

TEXT

Displays the graph level configuration if set for the root task, otherwise 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

NUMBER

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.

Usage notes¶

  • Latency for the view may be up to 45 minutes.

  • For increased performance, filter queries on the COMPLETED_TIME or SCHEDULED_TIME column.

Examples¶

Retrieve records for the 10 most recent completed task runs:

SELECT query_text, completed_time
FROM snowflake.account_usage.task_history
ORDER BY completed_time DESC
LIMIT 10;
Copy

Retrieve records for task runs completed in the past hour:

SELECT query_text, completed_time
FROM snowflake.account_usage.task_history
WHERE completed_time > DATEADD(hours, -1, CURRENT_TIMESTAMP());
Copy