CREATE TASK GRAPH

statementnot supportedUDFs, procedures, tasks, alerts, scriptingpreview

docs.snowflake.com ↗

Object: TASK GRAPH

Creates a Task Graph Object — a first-class database object that encapsulates a set of member tasks and their graph-wide settings. This command supports the following variants: - CREATE OR ALTER TASK GRAPH: Creates the task graph if it doesn’t exist, or alters an existing one to match the statement. - DEFINE TASK GRAPH: Declarative definition of a task graph, including its desired state, inside a DCM project. Important Member tasks are created and altered with the standard CREATE TASK and ALTER TASK commands. CREATE TASK GRAPH only creates the graph object over an existing set of tasks connected by AFTER relationships.

Syntax

supportedpartialnot supportednot scored

CREATE [ OR REPLACE ] TASK GRAPH [ IF NOT EXISTS ] <name>
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
  [ WITH CONTACT ( <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ) ]
  [ SCHEDULE = { '<num> { HOURS | MINUTES | SECONDS }'
               | 'USING CRON <expr> <time_zone>' } ]
  [ ROOTS = ( <root_task_name> ) ]
  [ FINALIZER = <finalizer_task_name> ]
  [ OVERLAP_POLICY = { NO_OVERLAP | ALLOW_CHILD_OVERLAP | ALLOW_ALL_OVERLAP } ]
  [ ERROR_INTEGRATION = <integration_name> ]
  [ SUCCESS_INTEGRATION = <integration_name> ]
  [ CONFIG = <configuration_string> ]
  [ TASK_AUTO_RETRY_ATTEMPTS = <num> ]
  [ SUSPEND_TASK_AFTER_NUM_FAILURES = <num> ]
  [ COMMENT = '<string>' ]
  [ TASK_DEFAULTS ( <default_property> = <value>
                    [ , <default_property> = <value> ... ] ) ]
  [ WHEN <condition> ]

Creates the graph if it doesn’t exist, or updates an existing graph to match the statement. Any property the statement omits is unset or reset to its default on the existing graph: for example, omitting FINALIZER removes the finalizer, and omitting TASK_DEFAULTS removes all task defaults.

CREATE OR ALTER TASK GRAPH <name>
  [ SCHEDULE = { '<num> { HOURS | MINUTES | SECONDS }'
               | 'USING CRON <expr> <time_zone>' } ]
  [ ROOTS = ( <root_task_name> ) ]
  [ FINALIZER = <finalizer_task_name> ]
  [ OVERLAP_POLICY = { NO_OVERLAP | ALLOW_CHILD_OVERLAP | ALLOW_ALL_OVERLAP } ]
  [ ERROR_INTEGRATION = <integration_name> ]
  [ SUCCESS_INTEGRATION = <integration_name> ]
  [ CONFIG = <configuration_string> ]
  [ TASK_AUTO_RETRY_ATTEMPTS = <num> ]
  [ SUSPEND_TASK_AFTER_NUM_FAILURES = <num> ]
  [ COMMENT = '<string>' ]
  [ TASK_DEFAULTS ( <default_property> = <value>
                    [ , <default_property> = <value> ... ] ) ]
  [ WHEN <condition> ]

Parameters

NameRequiredDescription
nameString that specifies the identifier for the task graph; must be unique for the schema in which it is created. For more details, see Identifier requirements.
SCHEDULE = ...Specifies the schedule for periodically running the graph. A schedule must be defined, or a WHEN condition set, for the graph to be resumable; otherwise it only runs when manually triggered with EXECUTE TASK GRAPH.
ROOTS = ( root_task_name )Specifies the root task of the graph. A task graph has exactly one root, so the list must contain exactly one task. You can create a graph without ROOTS and set it later. The graph must have a root before you can commit, resume, or execute it.
FINALIZER = finalizer_task_nameSpecifies the name of a task that runs after every other task in the graph completes, used for cleanup or notifications. This replaces the per-task FINALIZE property that root-task-based graphs use.
OVERLAP_POLICY = { NO_OVERLAP | ALLOW_CHILD_OVERLAP | ALLOW_ALL_OVERLAP }Specifies the overlap policy for graph runs. See Optional parameters for the equivalent task-level semantics. Default: NO_OVERLAP
ERROR_INTEGRATION = integration_nameSpecifies the name of the notification integration used to send error notifications for the graph.
SUCCESS_INTEGRATION = integration_nameSpecifies the name of the notification integration used to send success notifications for the graph.
CONFIG = configuration_stringSpecifies a configuration string in valid JSON format that all tasks in the graph can access.
TASK_AUTO_RETRY_ATTEMPTS = numSpecifies the number of automatic retry attempts for the graph after a failed run. Values: 0 - 30. Default: 0
SUSPEND_TASK_AFTER_NUM_FAILURES = numSpecifies the number of consecutive failed graph runs after which the graph is suspended automatically.
COMMENT = 'string'Specifies a comment for the task graph.
TASK_DEFAULTS ( default_property = value [ , ... ] )Specifies default settings that cascade to every member task unless the member overrides them. Only the following properties are supported: WAREHOUSE, USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE, TARGET_COMPLETION_INTERVAL, SERVERLESS_TASK_MIN_STATEMENT_SIZE, SERVERLESS_TASK_MAX_STATEMENT_SIZE, USER_TASK_TIMEOUT_MS, EXECUTE AS USER <user_name>, COMMENT, LOG_LEVEL, and TRACE_LEVEL.
WHEN conditionSpecifies a Boolean SQL expression that must be true for a graph run to start. If the root task also has a WHEN condition, both must be true. The graph’s condition applies only to starting the run; it isn’t evaluated again for the other member tasks.

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE TASK | Schema | Task graphs use the CREATE TASK privilege; there is no separate privilege for creating a task graph. EXECUTE TASK | Account | Required to run the graph. EXECUTE MANAGED TASK | Account | Required only if member tasks use serverless compute. USAGE | Integration | Required on any integration named in ERROR_INTEGRATION or SUCCESS_INTEGRATION. OWNERSHIP | Task | The tasks named in ROOTS and FINALIZER must be owned by the same role that owns the graph. Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

See also

Referenced by