Skip to main content

alias

Specify a custom alias for a model in your dbt_project.yml file, models/properties.yml file, or config block in a SQL file.

For example, if you have a model that calculates sales_total and want to give it a more user-friendly alias, you can alias it as shown in the following examples.

In the dbt_project.yml file, the following example sets a default alias for the sales_total model at the project level:

dbt_project.yml
models:
your_project:
sales_total:
+alias: sales_dashboard

The following specifies an alias as part of the models/properties.yml file metadata, useful for centralized configuration:

models/properties.yml
version: 2

models:
- name: sales_total
config:
alias: sales_dashboard

The following assigns the alias directly in the In models/sales_total.sql file:

models/sales_total.sql
{{ config(
alias="sales_dashboard"
) }}

This would return analytics.finance.sales_dashboard in the database, instead of the default analytics.finance.sales_total.

Definition

Optionally specify a custom alias for a model, data test, snapshot, or seed.

When dbt creates a relation (table/view) in a database, it creates it as: {{ database }}.{{ schema }}.{{ identifier }}, e.g. analytics.finance.payments

The standard behavior of dbt is:

  • If a custom alias is not specified, the identifier of the relation is the resource name (i.e. the filename).
  • If a custom alias is specified, the identifier of the relation is the {{ alias }} value.

Note With an ephemeral model, dbt will always apply the prefix __dbt__cte__ to the CTE identifier. This means that if an alias is set on an ephemeral model, then its CTE identifier will be __dbt__cte__{{ alias }}, but if no alias is set then its identifier will be __dbt__cte__{{ filename }}.

To learn more about changing the way that dbt generates a relation's identifier, read Using Aliases.

0