EXECUTE DCM

statementnot supportedContainer services & dev toolingpreview

docs.snowflake.com ↗

Plans or deploys DCM definitions that you write inline, without a DCM Project object. This form is called inline DCM. For when to use inline DCM, how it differs from a DCM project, and more examples, see Inline DCM. EXECUTE DCM ... PLAN performs a dry run. It validates whether the definitions would run successfully and reports their impact on existing objects in the changeset, but doesn’t apply any changes. EXECUTE DCM ... DEPLOY applies those changes.

Syntax

EXECUTE DCM { PLAN | DEPLOY } FROM
  BEGIN
    <definitions>
  END

Parameters

NameRequiredDescription
PLANrequiredInstructs Snowflake to perform a dry run. Snowflake analyzes the changes that would be applied, but doesn’t apply any changes.
DEPLOYrequiredApplies the changes defined in the BEGIN ... END block. DEPLOY first plans the changes, and then applies them. It doesn’t execute a PLAN result that you saved earlier. DEPLOY isn’t atomic and doesn’t run in a transaction. If the internal plan fails, no changes are applied. If the deployment fails while it applies the changes, the changes applied before the failure remain, and Snowflake doesn’t roll them back. For more information, see Deploy the definitions.
FROM BEGIN ... ENDrequiredThe inline definitions. FROM is required.

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: The statement runs with the privileges of the primary role that executes it, and ignores secondary roles. The role must own each existing object that the definitions change or grant privileges on, and it needs the privilege to create each new object. 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.

Output

EXECUTE DCM ... PLAN and EXECUTE DCM ... DEPLOY return one row that contains a JSON changeset. For the format, see PLAN and DEPLOY output. The metadata object contains the timestamp, query_id, user, role_name, and command fields, where command is PLAN or DEPLOY. In Workspaces, the results pane renders the changeset on the DCM tab. For more information, see Review the changeset. Query history shows each EXECUTE DCM statement as one query. The individual changes that DEPLOY applies, such as creating a table or granting a privilege, don’t appear as separate queries. To see what a DEPLOY changed, review the changeset that it returns.

Supported clients and interfaces

You can run EXECUTE DCM from a client that sends the whole statement to Snowflake, including the semicolons inside the BEGIN ... END block. A client that splits SQL text at semicolons sends only the text up to the first semicolon, and Snowflake rejects that text with a syntax error. Client or interface | Support Workspaces | Supported in SQL files. The results pane renders the changeset on the DCM tab. Snowflake CLI | The snow sql command supports EXECUTE DCM in version 3.35.0 and later. Earlier versions split the block. The snow stage execute command isn’t supported, because it runs files with EXECUTE IMMEDIATE FROM. Snowflake Scripting, stored procedures, tasks, and alerts | Supported. You can run the statement in a Snowflake Scripting block, in a SQL, Python, JavaScript, or Java stored procedure, as the body of a task, or as the action of an alert. EXECUTE IMMEDIATE and EXECUTE IMMEDIATE FROM | Not supported. Call a stored procedure that runs the statement instead. Python connector | Supported with cursor.execute() and cursor.execute_async(). Not supported with connection.execute_string() or connection.execute_stream(), which split the block. Snowpark Python | Supported with session.sql(...).collect() and session.sql(...).show(). Don’t use to_pandas(): it returns an error after Snowflake has run the statement, so an EXECUTE DCM ... DEPLOY is applied even though to_pandas() fails. JDBC, Go, and .NET drivers | Supported. To get the changeset, use a method that returns a result set: executeQuery() in JDBC, QueryContext() in Go, or ExecuteReader() in .NET. execute() and executeUpdate() in JDBC, ExecContext() in Go, and ExecuteNonQuery() in .NET run the statement but don’t return the changeset. Node.js driver | Supported. Snowflake SQL API | Supported. Snowflake Terraform provider | Supported in the snowflake_execute resource. SnowSQL | Not supported with the default ; delimiter, because SnowSQL splits the block. Use Snowflake CLI instead. Other tools that split SQL scripts at semicolons have the same limitation, for example schemachange, or the Snowflake provider for Apache Airflow with its default settings. Turn off statement splitting in the tool if it has an option for it, or call a stored procedure that runs the statement. To send EXECUTE DCM together with other statements in one request, use the multi-statement mode of the client, for example by setting the MULTI_STATEMENT_COUNT parameter to 0. The whole EXECUTE DCM statement counts as one statement.

See also

Referenced by