CREATE TASK GRAPH¶
Creates, or creates and alters, 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:
- sqlsyntax: Creates a new task graph object.
- CREATE OR ALTER TASK GRAPH: Creates the task graph if it doesn’t exist, or alters an existing one to match the statement.
- See also:
ALTER TASK GRAPH, DROP TASK GRAPH, EXECUTE TASK GRAPH, SHOW TASK GRAPHS, DESCRIBE TASK GRAPH
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¶
Variant syntax¶
CREATE OR ALTER TASK GRAPH¶
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.
Note
CREATE OR ALTER TASK GRAPH does not resume or suspend a graph. Use ALTER TASK GRAPH for lifecycle management.
Parameters¶
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
WHENcondition 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
ROOTSand 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
FINALIZEproperty 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_OVERLAPERROR_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:0SUSPEND_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, andTRACE_LEVEL.WHEN conditionSpecifies a Boolean SQL expression that must be true for a graph run to start. If the root task also has a
WHENcondition, both must be true. The graph’s condition applies only to starting the run; it isn’t evaluated again for the other member tasks.
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.
Usage notes¶
- A newly created task graph is not started. It must be committed with ALTER TASK GRAPH … COMMIT and then resumed with ALTER TASK GRAPH … RESUME before it runs on its schedule.
TASK_DEFAULTSsupplied here is the initial set. A laterSET TASK_DEFAULTSperforms a merge into the existing set, not a replace — see ALTER TASK GRAPH.- Set
SCHEDULE,OVERLAP_POLICY,ERROR_INTEGRATION,SUCCESS_INTEGRATION,TASK_AUTO_RETRY_ATTEMPTS,SUSPEND_TASK_AFTER_NUM_FAILURES, andCONFIGon the graph. Setting them on a member task returns an error. A finalizer is also declared on the graph withFINALIZER, instead of on the finalizer task withFINALIZE. - The tasks named in
ROOTSandFINALIZERmust be owned by the role that owns the graph.
Examples¶
Create the graph if it doesn’t exist, or update it in place: