Categories:

Information Schema , Table functions

DBT_PROJECT_EXECUTION_HISTORY

Returns the execution history of dbt Projects on Snowflake.

Call this function to get metadata and results from past dbt Project executions within seven days of the current time. Optionally, specify the values to filter the results by.

Use this function with the following system functions to access dbt artifacts and logs programmatically:

For more information, see Access dbt artifacts and logs programmatically.

See also:

CREATE DBT PROJECT, EXECUTE DBT PROJECT, DBT_PROJECT_EXECUTION_HISTORY view (Account Usage)

Syntax

DBT_PROJECT_EXECUTION_HISTORY (
  [ OBJECT_NAME => '<name>' ]
  [ , OBJECT_TYPE = { WORKSPACE | DBT PROJECT }]
  [ , START_TIME_RANGE_START => <start_time> ]
  [ , START_TIME_RANGE_END => <end_time>  ]
  [ , RESULT_LIMIT = <integer> ]
  [ , COMMAND = <dbt_command> ]
  [ , USER_NAME = <user_name> ]
  [ , DATABASE = <db_name> ]
  [ , SCHEMA = <schema_name> ]
)

Arguments

OBJECT_NAME = <name>

Name of the workspace or dbt project object that the execution belongs to.

In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive.

For more information, see Identifier requirements.

OBJECT_TYPE = { WORKSPACE | DBT PROJECT }

The type of the object, WORKSPACE or DBT PROJECT, the execution belongs to.

START_TIME_RANGE_START | START_TIME_RANGE_END = timestamp

Timestamp to filter a range of executions.

RESULT_LIMIT = integer

An integer specifying the maximum number of rows returned by the function, from 1 - 10,000 inclusive.

Default: 100

COMMAND = dbt_command

Specifies the dbt command used to execute the dbt project object.

USER_NAME = user_name

Name of the user that initiated the dbt project object execution.

DATABASE = db_name

Return only records for the specified database.

SCHEMA = schema_name

Return only records for the specified schema.

Output

The function returns the following columns.

To view these columns, you must use a role with the MONITOR privilege.

Column NameData TypeDescription
QUERY_IDTEXTID of the query.
QUERY_START_TIMETIMESTAMP_LTZThe time the query started.
QUERY_END_TIMETIMESTAMP_LTZThe time the query ended. For an execution that is still running (STATE is RUNNING), this column doesn’t contain a valid end time.
USER_NAMETEXTThe user that ran the execution.
OBJECT_NAMETEXTName of the workspace or dbt project object the execution belonged to.
OBJECT_TYPETEXTType of object, such as WORKSPACE or DBT PROJECT.
DATABASE_NAMETEXTDatabase of the object.
SCHEMA_NAMETEXTSchema of the object.
COMMANDTEXTThe command that was run for the object.
ARGSTEXTThe arguments that were used in the run for the object.
ERROR_CODETEXTIf applicable, the error code for the run.
ERROR_MESSAGETEXTIf applicable, error message stating why the run failed.
WAREHOUSETEXTWarehouse used for the object.
STATETEXTState of the run. One of the following values:
  • RUNNING: The execution is in progress.
  • SUCCESS: The dbt command completed successfully.
  • HANDLED_ERROR: The dbt command ran but reported a failure, such as a failed model or test.
  • UNHANDLED_ERROR: The execution failed before completing all of its models or tests, for example because the query was canceled or the profiles.yml file is invalid.
The distinction between HANDLED_ERROR and UNHANDLED_ERROR applies only to dbt 1.x projects. For dbt 2.x projects, a failed execution is reported as HANDLED_ERROR, even if it fails before running any models or tests (for example, because the dbt_project.yml file is invalid).
DBT_VERSIONTEXTThe version of dbt Core used to run the project, such as 1.9.4. This is the version of the dbt engine, not a version of your dbt project.
DBT_SNOWFLAKE_VERSIONTEXTThe version of the dbt-snowflake adapter package used for the run, such as 1.9.2. This is not a version of your dbt project.
ENVIRONMENTTEXTThe environment (defined in the env.yml file) used for this run. NULL if the run didn’t use an environment. For more information, see Use SQL environment variables and private Git packages.
WRITEBACKBOOLEANWhether the run wrote its generated target and log files back to the live version of the dbt project object. This is the effective value for the run: the WRITEBACK value specified in EXECUTE DBT PROJECT if present; otherwise, the object’s DEFAULT_WRITEBACK value.
TARGET_PATHTEXTThe dbt target directory used for the run, relative to the dbt project root, such as target. Reflects the --target-path flag or a target path environment variable, such as DBT_TARGET_PATH, if set; otherwise, the dbt default. NULL if the path wasn’t recorded for the run.
LOG_PATHTEXTThe dbt log directory used for the run, relative to the dbt project root, such as logs. Reflects the --log-path flag or a log path environment variable, such as DBT_LOG_PATH, if set; otherwise, the dbt default. NULL if the path wasn’t recorded for the run.
LAST_DEPLOYED_FROMVARIANTInformation about where the dbt project object was most recently deployed from, such as a Git repository or a stage. Depending on the source, it can contain git_url or stage_url, git_commit, git_branch, user, and timestamp fields. The value is recorded when the run starts, so later deployments of the project don’t change it. NULL for workspace runs and for dbt project objects with no recorded deployment metadata. This value comes from the last_deployed_from column returned by SHOW DBT PROJECTS.

Access control requirements

This table function includes only runs from workspaces and dbt Projects in which you have the following privileges:

  • OWNERSHIP, READ, or WRITE on workspaces
  • OWNERSHIP, USAGE, or MONITOR on dbt Projects

Usage notes

  • Use the exact dbt project object name (case-sensitive if created with quotes). If no row matches (wrong name or no executions yet), you might get an Inputs may not be null. error.
  • Use function arguments such as DATABASE, SCHEMA, and OBJECT_NAME to filter results whenever possible. These filters are applied before the RESULT_LIMIT (default: 100 rows), so using them ensures you get the most relevant results rather than filtering a potentially truncated result set with a WHERE clause.

Examples

The following example audits which engine version was used for recent runs:

SELECT
    object_name,
    query_start_time,
    query_end_time,
    query_id,
    command,
    state
FROM TABLE (
    SNOWFLAKE.INFORMATION_SCHEMA.DBT_PROJECT_EXECUTION_HISTORY(
      DATABASE => 'ANALYTICS_DB',
      SCHEMA => 'DBT_PROD',
      OBJECT_NAME => 'FINANCE_ANALYTICS'
    )
  )
ORDER BY query_end_time DESC;

For detailed examples of using the DBT_PROJECT_EXECUTION_HISTORY table function with system functions to access dbt artifacts and logs programmatically, see Access dbt artifacts and logs programmatically.