- Categories:
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¶
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 = timestampTimestamp to filter a range of executions.
RESULT_LIMIT = integerAn integer specifying the maximum number of rows returned by the function, from 1 - 10,000 inclusive.
Default: 100
COMMAND = dbt_commandSpecifies the dbt command used to execute the dbt project object.
USER_NAME = user_nameName of the user that initiated the dbt project object execution.
DATABASE = db_nameReturn only records for the specified database.
SCHEMA = schema_nameReturn 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 Name | Data Type | Description |
|---|---|---|
| QUERY_ID | TEXT | ID of the query. |
| QUERY_START_TIME | TIMESTAMP_LTZ | The time the query started. |
| QUERY_END_TIME | TIMESTAMP_LTZ | The time the query ended. For an execution that is still running (STATE is RUNNING), this column doesn’t contain a valid end time. |
| USER_NAME | TEXT | The user that ran the execution. |
| OBJECT_NAME | TEXT | Name of the workspace or dbt project object the execution belonged to. |
| OBJECT_TYPE | TEXT | Type of object, such as WORKSPACE or DBT PROJECT. |
| DATABASE_NAME | TEXT | Database of the object. |
| SCHEMA_NAME | TEXT | Schema of the object. |
| COMMAND | TEXT | The command that was run for the object. |
| ARGS | TEXT | The arguments that were used in the run for the object. |
| ERROR_CODE | TEXT | If applicable, the error code for the run. |
| ERROR_MESSAGE | TEXT | If applicable, error message stating why the run failed. |
| WAREHOUSE | TEXT | Warehouse used for the object. |
| STATE | TEXT | State of the run. One of the following values:
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_VERSION | TEXT | The 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_VERSION | TEXT | The 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. |
| ENVIRONMENT | TEXT | The 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. |
| WRITEBACK | BOOLEAN | Whether 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_PATH | TEXT | The 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_PATH | TEXT | The 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_FROM | VARIANT | Information 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, andOBJECT_NAMEto filter results whenever possible. These filters are applied before theRESULT_LIMIT(default: 100 rows), so using them ensures you get the most relevant results rather than filtering a potentially truncated result set with aWHEREclause.
Examples¶
The following example audits which engine version was used for recent runs:
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.