About target variables | dbt Developer Hub
Skip to main content

About target variables

The target variable contains information about your connection to the warehouse.

  • dbt Core: These values are based on the target defined in your profiles.yml file. Please note that for certain adapters, additional configuration steps may be required. Refer to the set up page for your data platform.
  • dbt Cloud To learn more about setting up your adapter in dbt Cloud, refer to About data platform connections.
    • dbt Cloud Scheduler: target.name is defined per job as described in Custom target names. For other attributes, values are defined by the deployment connection. To check these values, click Deploy and select Environments. Then, select the relevant deployment environment, and click Settings.
    • dbt Cloud IDE: These values are defined by your connection and credentials. To edit these values, click on your account name in the left side menu and select Account settings. Then, click Credentials. Select and edit a project to set up the credentials and target name.

Some configurations are shared between all adapters, while others are adapter-specific.

Common

VariableExampleDescription
target.profile_namejaffle_shopThe name of the active profile
target.namedevName of the active target
target.schemadbt_aliceName of the dbt schema (or, dataset on BigQuery)
target.typepostgresThe active adapter being used. One of "postgres", "snowflake", "bigquery", "redshift", "databricks"
target.threads4The number of threads in use by dbt

Adapter-specific

Snowflake

VariableExampleDescription
target.databaseRAWDatabase name specified in active target.
target.warehouseTRANSFORMName of the Snowflake virtual warehouse
target.userTRANSFORM_USERThe user specified in the active target
target.roleTRANSFORM_ROLEThe role specified in the active target
target.accountabc123The account specified in the active target

Postgres/Redshift

VariableExampleDescription
target.dbnameanalyticsDatabase name specified in active target.
target.hostabc123.us-west-2.redshift.amazonaws.comThe host specified in active target
target.userdbt_userThe user specified in the active target
target.port5439The port specified in the active profile

BigQuery

VariableExampleDescription
target.projectabc-123The project specified in the active profile
target.datasetdbt_aliceThe dataset the active profile

Examples

Use target.name to limit data in dev

As long as you use sensible target names, you can perform conditional logic to limit data when working in dev.

select
*
from source('web_events', 'page_views')
{% if target.name == 'dev' %}
where created_at >= dateadd('day', -3, current_date)
{% endif %}

Use target.name to change your source database

If you have specific Snowflake databases configured for your dev/qa/prod environments, you can set up your sources to compile to different databases depending on your environment.

version: 2

sources:
- name: source_name
database: |
{%- if target.name == "dev" -%} raw_dev
{%- elif target.name == "qa" -%} raw_qa
{%- elif target.name == "prod" -%} raw_prod
{%- else -%} invalid_database
{%- endif -%}
schema: source_schema
0