ALTER TASK

statementsupportedUDFs, procedures, tasks, alerts, scripting

docs.snowflake.com ↗

Object: TASK

Modifies the properties for an existing task. For information about tasks, see Introduction to tasks.

Syntax

supportedpartialnot supportednot scored

ALTER TASK [ IF EXISTS ] <name> RESUME | SUSPEND

ALTER TASK [ IF EXISTS ] <name> REMOVE AFTER <string> [ , <string> , ... ]
  | ADD AFTER <string> [ , <string> , ... ]

ALTER TASK [ IF EXISTS ] <name> SET
  [ { WAREHOUSE = <string> }
    | { USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE = <string> } ]
  [ SCHEDULE = { '<num> { HOURS | MINUTES | SECONDS }'
               | 'USING CRON <expr> <time_zone>' } ]
  [ CONFIG = <configuration_string> ]
  [ OVERLAP_POLICY = { NO_OVERLAP | ALLOW_CHILD_OVERLAP | ALLOW_ALL_OVERLAP } ]
  [ USER_TASK_TIMEOUT_MS = <num> ]
  [ SUSPEND_TASK_AFTER_NUM_FAILURES = <num> ]
  [ ERROR_INTEGRATION = <integration_name> ]
  [ SUCCESS_INTEGRATION = <integration_name> ]
  [ LOG_LEVEL = '<log_level>' ]
  [ COMMENT = <string> ]
  [ <session_parameter> = <value>
    [ , <session_parameter> = <value> ... ] ]
  [ TASK_AUTO_RETRY_ATTEMPTS = <num> ]
  [ USER_TASK_MINIMUM_TRIGGER_INTERVAL_IN_SECONDS = <num> ]
  [ TARGET_COMPLETION_INTERVAL = '<num> { HOURS | MINUTES | SECONDS }' ]
  [ SERVERLESS_TASK_MIN_STATEMENT_SIZE= 'XSMALL | SMALL
    | MEDIUM | LARGE | XLARGE | XXLARGE' ]
  [ SERVERLESS_TASK_MAX_STATEMENT_SIZE= 'XSMALL | SMALL
    | MEDIUM | LARGE | XLARGE | XXLARGE' ]
  [ CONTACT <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ]
  [ EXECUTE AS USER <user_name> ]


ALTER TASK [ IF EXISTS ] <name> UNSET
  [ WAREHOUSE ]
  [ SCHEDULE ]
  [ CONFIG ]
  [ OVERLAP_POLICY ]
  [ USER_TASK_TIMEOUT_MS ]
  [ SUSPEND_TASK_AFTER_NUM_FAILURES ]
  [ LOG_LEVEL ]
  [ COMMENT ]
  [ <session_parameter> [ , <session_parameter> ... ] ]
  [ TARGET_COMPLETION_INTERVAL ]
  [ SERVERLESS_TASK_MIN_STATEMENT_SIZE ]
  [ SERVERLESS_TASK_MAX_STATEMENT_SIZE ]
  [ CONTACT <purpose> [ , ... ]]
  [ EXECUTE AS USER ]


ALTER TASK [ IF EXISTS ] <name> SET TAG <tag_name> = '<tag_value>'
  [ , <tag_name> = '<tag_value>' ... ]

ALTER TASK [ IF EXISTS ] <name> UNSET TAG <tag_name> [ , <tag_name> ... ]

ALTER TASK [ IF EXISTS ] <name> SET FINALIZE = <string>

ALTER TASK [ IF EXISTS ] <name> UNSET FINALIZE

ALTER TASK [ IF EXISTS ] <name> MODIFY AS <sql>

ALTER TASK [ IF EXISTS ] <name> MODIFY WHEN <boolean_expr>

ALTER TASK [ IF EXISTS ] <name> REMOVE WHEN

Parameters

NameRequiredDescription
nameIdentifier for the task to alter. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.
RESUME | SUSPENDSpecifies the action to perform on the task: RESUME brings a suspended task to the ‘Started’ state. Note that accounts are currently limited to a maximum of 30000 started tasks. Before resuming the root task of your Task Graph, resume all child tasks. To recursively resume the root task’s child tasks, use SYSTEM$TASK_DEPENDENTS_ENABLE. SUSPEND puts the task into a ‘Suspended’ state. If the task schedule is set to an interval of (number { HOURS | MINUTES | SECONDS }), the base interval time for the schedule is reset to the current time the task is resumed. The base interval time starts the interval counter from the current clock time. For example, if an INTERVAL value of 10 MINUTES is set and the task is resumed at 9:03 AM, then the task runs at 9:13 AM, 9:23 AM, and so on. Note that we only guarantee that tasks don’t execute before their set interval occurs. In the current example, the task could first run at 9:14 AM, but won’t run at 9:12 AM.
REMOVE AFTER string [ , string , ... ]Specifies the names of one or more current predecessor tasks for this child task in a task graph. When all predecessors for a child task are removed, then the former child task becomes either a standalone task or a root task, depending on whether other tasks identify this former child task as their predecessor. If the former child task becomes a root task, this task is suspended by default and must be resumed manually.
ADD AFTER string [ , string , ... ]Specifies the names of one or more existing tasks to add as predecessors for this child task in a task graph. Each child task in a task graph runs when all predecessor tasks finish their runs successfully. For more information, see the description of the AFTER parameter in CREATE TASK. Each child task is limited to 100 predecessor tasks.
SET ...Specifies either or both of the following: One or more properties to set for the task, which are separated by blank spaces, commas, or new lines. For more details about the properties you can set, see CREATE TASK. When you set the configuration on a task, you specify the default configuration string for the task. You can override the default configuration for a single execution by using the EXECUTE TASK command. A comma-separated list of session parameters to set for the session when the task runs. A task supports all session parameters. For the complete list, see Parameters.
TAG tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ]Specifies the tag name and the tag string value. The tag value is always a string, and the maximum number of characters for the tag value is 256. For information about specifying tags in a statement, see Tag quotas.
CONTACT purpose = contact [ , purpose = contact ... ]Associate the existing object with one or more contacts. For a list of valid purposes, see Associate a contact with an object. You cannot set the CONTACT property with other properties in the same statement.
UNSET ...Specifies one (or more) properties and/or session parameters to unset for the task, which resets them to the defaults. You can reset multiple properties/parameters with a single ALTER statement; however, each property/parameter must be separated by a comma. When resetting a property/parameter, specify only the name; specifying a value for the property/parameter will return an error. To detach a contact from the task, specify UNSET CONTACT purpose. You cannot unset the CONTACT property with other properties in the same statement.
sqlSpecifies the SQL code to execute when the task runs: Single SQL statement Call to a stored procedure Procedural logic using Snowflake Scripting Note that currently, Snowsight does not support creating or modifying tasks to use Snowflake Scripting. Instead, use SnowSQL or another command-line client. Note Verify that the SQL code you reference in a task executes as expected before you create the task. Tasks are intended to automate SQL code that has already been tested thoroughly.
WHEN boolean_exprSpecifies a Boolean SQL expression. When a task is triggered, it validates the conditions of the expression to determine whether to execute. If the conditions of the expression are not met, then the task skips the current run. Any tasks that identify this task as a predecessor also don’t run, unless the task graph uses advanced branching. In a task graph that uses advanced branching, every task is scheduled and evaluates its own WHEN clause, whatever state its predecessors completed in. Validating the conditions of the WHEN expression does not require a virtual warehouse. The validation is instead processed in the cloud services layer. A nominal charge accrues each time a task evaluates its WHEN condition and does not run. The charges accumulate each time the task is triggered until it runs. At that time, the charge is converted to Snowflake credits and added to the compute resource usage for the task run. Generally the compute time to validate the condition is insignificant compared to task execution time. As a best practice, align scheduled and actual task runs as closely as possible. Avoid task schedules that are wildly out of sync with actual task runs. For example, if data is inserted into a table with a stream roughly every 24 hours, don’t schedule a task that checks for stream data every minute. The charge to validate the WHEN expression with each run is generally insignificant, but the charges are cumulative. Note that daily consumption of cloud services that falls below the 10% quota of the daily usage of the compute resources accumulates no cloud services charges. Currently, the following functions are supported for evaluation in the SQL expression: Preview Feature — Open SYSTEM$PREDECESSORS_STATE and SYSTEM$TASK_COMPLETION_STATE are public preview features, available to all accounts. Note Adding SYSTEM$PREDECESSORS_STATE or SYSTEM$TASK_COMPLETION_STATE to any task in a task graph changes how Snowflake schedules every task in that graph. Removing the last call to either function from a graph reverts the graph to the default scheduling behavior. For details, see How advanced branching changes scheduling.
  • SYSTEM$STREAM_HAS_DATA — Indicates whether a specified stream contains change tracking data. Used to run a triggered task if no schedule is defined for the task. You can also use this to skip the current task run if the stream contains no change data. If the result is FALSE, then the task does not run.
  • SYSTEM$GET_PREDECESSOR_RETURN_VALUE — Retrieves the return value for the predecessor task in a task graph. Used to decide whether the task should run based on the returned result.
  • SYSTEM$PREDECESSORS_STATE — Indicates whether the predecessors of the task completed in the states described by a specified condition, such as ALL_FAILED or ALL_DONE. Used to run a task on outcomes other than “all predecessors succeeded.”
  • SYSTEM$TASK_COMPLETION_STATE — Returns the state that a specified task in the current task graph run completed in, such as SUCCEEDED, FAILED, or SKIPPED. Used to branch on the outcome of one specific task rather than on the outcome of all of the task’s predecessors.
REMOVE WHENRemove the WHEN condition that you have specified.
EXECUTE AS USER user_nameRuns the task on behalf of a specified user account. The user who runs the command must have permissions granted by using the GRANT IMPERSONATE ON USER TO ROLE command. For more information, see Run tasks with user privileges.

Usage notes

Rename a task

Renaming a task isn’t supported. Instead, you can clone the task, and then drop the old task; for example: - Suspend the task (ALTER TASK task_old_name SUSPEND). - Clone the task, giving it a new name (CREATE TASK new_task_name CLONE old_task_name). - For task graphs, find dependent tasks that refer to the old task name, and update them to use the new name: - Find immediately dependent tasks (that is, child tasks and finalizer tasks, but not children-of-children tasks) using the TASK_DEPENDENTS … RECURSIVE function; for example: Copy code SELECT * FROM TABLE(INFORMATION_SCHEMA.TASK_DEPENDENTS('old_task_name', RECURSIVE => false)); - Update each dependent task to use the new task name (ALTER TASK child_task_1 ADD AFTER new_task_name). - Drop the old version of the task (DROP TASK old_task_name). - Resume the new version of the task (ALTER TASK new_task_name RESUME).

See also

Referenced by