EXECUTE DBT PROJECT

statementsupportedContainer services & dev tooling

docs.snowflake.com ↗

Executes the specified dbt project object or the dbt project in a Snowflake workspace using the dbt command and command-line options specified.

Syntax

supportedpartialnot supportednot scored

Executes the dbt project object with the specified name.

EXECUTE DBT PROJECT [ IF EXISTS ] <name>
  [ ARGS = '[ <dbt_command> ] [ --<dbt_cli_option> <option_value_1> [ ... ] ] [ ... ]' ]
  [ DBT_VERSION = '<version_number>' ]
  [ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , ... ] ) ]
  [ ENVIRONMENT = '<environment_name>' ]
  [ ENV_VARS = ( '<key>' = '<value>' [ , ... ] ) ]
  [ IMPORTS = ( { '<source_location>' | <system_function> } [ AS '<alias>' ] [ , ... ] ) ]
  [ WRITEBACK = { TRUE | FALSE } ]

Executes the dbt project that is saved in a workspace with the specified workspace name. The user who owns the workspace must be the user who runs this command variant.

EXECUTE DBT PROJECT [ IF EXISTS ] [ FROM WORKSPACE <name> ]
  [ ARGS = '[ <dbt_command> ] [ --<dbt_cli_option> <option_value_1> [ ... ] [ ... ] ]' ]
  [ DBT_VERSION = '<version_number>' ]
  [ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , ... ] ) ]
  [ ENVIRONMENT = '<environment_name>' ]
  [ ENV_VARS = ( '<key>' = '<value>' [ , ... ] ) ]
  [ IMPORTS = ( { '<source_location>' | <system_function> } [ AS '<alias>' ] [ , ... ] ) ]
  [ PROJECT_ROOT = '<subdirectory_path>' ]

Parameters

NameRequiredDescription
namerequiredWhen executing a dbt project object, specifies the name of the dbt project object to execute. When executing a dbt project by using the FROM WORKSPACE option, specifies the name of the workspace for dbt Projects on Snowflake. The workspace name is always specified in reference to the public schema in the user’s personal database, which is indicated by user$. We recommend enclosing the workspace name in double quotes because workspace names are case-sensitive and can contain special characters. The following example shows a workspace name reference: user$.public."My dbt Project Workspace"
ARGS = '[ dbt_command ] [ --dbt_cli_option option_value_1 [ ... ] [ ... ] ]'optionalSpecifies the dbt command and supported command-line options to use when the dbt project object executes. This is a literal string that must conform to the syntax and requirements of dbt CLI commands. If no value is specified, the dbt project object executes with the dbt command and command-line options specified in the dbt project object definition. If you specify dbt CLI options without specifying a dbt command, the dbt run command executes by default. Default: No value
DBT_VERSION = 'version_number'optionalSpecifies a version for the dbt project object. Default: When you execute a dbt project object, the system uses the default version you specified when creating the dbt project object. If no value is specified, the system defaults to the version set by the DEFAULT_DBT_VERSION account parameter. For more information, see Supported dbt versions for dbt Projects on Snowflake.
PROJECT_ROOT = 'subdirectory_path'optionalSpecifies the subdirectory path to the dbt_project.yml file within the dbt project object or workspace. This parameter is only supported when executing a dbt project by using the FROM WORKSPACE option. If no value is specified, the dbt project object executes with the dbt_project.yml file in the root directory of the dbt project object. If no dbt_project.yml file exists in the root directory or in the PROJECT_ROOT subdirectory, an error occurs. Default: No value
EXTERNAL_ACCESS_INTEGRATIONS = ( integration_name [ , ... ] )optionalSpecifies the external access integration that grants dbt outbound network access to external endpoints. Most commonly, this lets dbt pull remote packages from the dbt package hub or a Git provider such as GitHub when dbt deps runs during execution. If a command needs external access during execution (for example, dbt deps), specify EXTERNAL_ACCESS_INTEGRATIONS on the EXECUTE DBT PROJECT command. This also applies when your project resolves a Snowflake secret from an env.yml file to authenticate private Git packages. For more information, see Use SQL environment variables and private Git packages. For more information, see Understand dependencies for dbt Projects on Snowflake.
ENVIRONMENT = 'environment_name'optionalSelects the named environment defined in the project’s env.yml file for this execution. The environment determines which set of environment variables and secrets is injected before dbt runs. This argument takes the highest precedence for environment selection, overriding the DEFAULT_ENVIRONMENT set on the dbt project object and the default_environment in env.yml. To run without any environment, use the reserved name NO_ENV. Default: The dbt project object’s DEFAULT_ENVIRONMENT, or the default_environment: in env.yml if DEFAULT_ENVIRONMENT isn’t set. For more information, see Use SQL environment variables and private Git packages.
ENV_VARS = ( 'key' = 'value' [ , ... ] )optionalOverrides individual environment variables for a single execution. These overrides merge into the selected environment and take final precedence over values in env.yml. Keys must be prefixed with DBT_ and uppercase. Values can be SQL that resolves to a single VARCHAR value, string literals, session variables ($var), or bind placeholders (?). Snowflake secrets can’t be referenced directly in ENV_VARS; manage secrets through the env.yml file instead. Default: No value For more information, see Use SQL environment variables and private Git packages.
IMPORTS = ( { 'source_location' | system_function } [ AS 'alias' ] [ , ... ] )optionalWhen executing a deployed dbt project object or a dbt project in a workspace, makes files from one or more source locations available under the project’s ./imports directory. You can import from a stage, a deployed dbt project object, a workspace, or one of these system functions: SYSTEM$DBT_GET_LAST_SUCCESSFUL_RUN_TARGET SYSTEM$DBT_GET_LAST_FAILED_RUN_TARGET SYSTEM$DBT_GET_LAST_RUN_TARGET SYSTEM$LOCATE_DBT_ARTIFACTS SYSTEM$LOCATE_DBT_ARCHIVE Other system functions aren’t supported in IMPORTS. Use IMPORTS to reuse state from an earlier execution without copying artifacts into the live version. Snowflake makes files from each source location available under ./imports before dbt runs. State comparison uses manifest.json, result selection uses run_results.json, and source freshness comparison uses sources.json, when those files are present. Use AS '<alias>' to name the subdirectory for an import. For example, AS 'state' mounts the imported files at ./imports/state. The --state option in ARGS must point to the mounted directory. IMPORTS alone doesn’t tell dbt to use the files as state. For a complete example, see Run changed models by importing state from a production project. Without an alias, Snowflake derives a lowercase directory name in the form {lowercased object name}_{lowercased last folder name}. For example, @my_dbt_project/target/ mounts at ./imports/my_dbt_project_target, while a target directory from a dbt project object named DBT_PROD mounts at ./imports/dbt_prod_target. Use an alias when you want a shorter, more predictable path. Use SYSTEM$DBT_GET_LAST_SUCCESSFUL_RUN_TARGET to import dbt artifacts from the most recent successful execution of a dbt project object. The SYSTEM$DBT_GET_LAST_*_RUN_TARGET functions search for the most recent qualifying execution and import its target artifacts without dbt_artifacts.zip. Their default command filter is compile,build,run,docs generate. Specify source freshness explicitly to retrieve freshness results. Use SYSTEM$LOCATE_DBT_ARTIFACTS to import dbt artifacts from a specific query. When used in IMPORTS, SYSTEM$LOCATE_DBT_ARTIFACTS imports the results directory, including dbt_artifacts.zip, but doesn’t extract the ZIP file. The function mounts the results directory under ./imports/<alias>, so the dbt artifacts are under ./imports/<alias>/target. Use SYSTEM$LOCATE_DBT_ARCHIVE to import the full archived target and logs, such as compiled SQL. This function is the only way to extract a ZIP file into an execution, and an execution can extract at most one ZIP file. Snowflake doesn’t automatically extract ZIP files imported from other locations, such as a named stage. Importing the full archive can take longer than importing standalone artifacts. For details, see Results directory contents. Default: No value
WRITEBACK = { TRUE | FALSE }optionalWhen executing a deployed dbt project object, overrides its DEFAULT_WRITEBACK property for this execution: TRUE: Writes generated target and log files back to the mutable live version. For a deps execution, also writes the installed dbt_packages folder and package-lock.yml back to the live version. FALSE: Doesn’t write generated target and log files back to the live version. For a deps execution, the installed packages are not persisted in the dbt project object, so later executions can’t use them. To install packages that later executions can use, run deps with WRITEBACK = TRUE. For concurrent executions that don’t need to update the live version, Snowflake recommends WRITEBACK = FALSE. If writeback is required, use distinct, non-overlapping target and log directories for each execution. Snowflake stores the per-query result artifacts and archive regardless of this setting. Default: The dbt project object’s DEFAULT_WRITEBACK value.

Output

If the dbt project execution succeeds, the command returns a single row with the following columns. If the dbt project execution fails, the command doesn’t return a row. Instead, it fails with an error that includes the dbt error message. To retrieve the full dbt log for the failed execution, call SYSTEM$GET_DBT_LOG with the query ID of the failed execution. To retrieve the log files and artifacts that dbt writes to the /target directory, see Access dbt artifacts and logs programmatically. Column | Description SUCCESS | Always TRUE. This column is retained for backward compatibility; a failed execution returns an error instead of a row. EXCEPTION | Always the string None. This column is retained for backward compatibility; a failed execution returns an error instead of a row. STDOUT | The standard output returned by the dbt project execution.

Access control requirements

A role used to execute this SQL command must have at least one of the following privileges at a minimum: Privilege | Object USAGE | dbt project 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. Note The dbt command specified in EXECUTE DBT PROJECT runs with the privileges of the role specified in the outputs block of the project’s dbt_projects_profiles.yml or profiles.yml file. Operations are further restricted to only those privileges granted to the Snowflake user calling EXECUTE DBT PROJECT. Both the user and the role specified must have the required privileges to use the warehouse, perform operations on the database and schema specified in the profile file, and perform operations on any other Snowflake objects that the dbt model specifies. Snowflake uses dbt_projects_profiles.yml when both files are present.

See also

Referenced by