Skip to main content

target_schema

note

For versionless dbt Cloud accounts and dbt Core v1.9+, this functionality is no longer required. Use the schema config as an alternative to define a custom schema while still respecting the generate_schema_name macro.

dbt_project.yml
snapshots:
<resource-path>:
+target_schema: string

snapshots/<filename>.sql
{{ config(
target_schema="string"
) }}

Description

The schema that dbt should build a snapshot table into. Snapshots build into the same target_schema, no matter who is running them.

On BigQuery, this is analogous to a dataset.

Default

This is a required parameter, no default is provided.

Examples

Build all snapshots in a schema named snapshots

dbt_project.yml
snapshots:
+target_schema: snapshots

Use a target-aware schema

Use the {{ target }} variable to change which schema a snapshot table is built in.

Note: consider whether this use-case is right for you, as downstream refs will select from the dev version of a snapshot, which can make it hard to validate models that depend on snapshots (see above FAQ)

dbt_project.yml
snapshots:
+target_schema: "{% if target.name == 'prod' %}snapshots{% else %}{{ target.schema }}{% endif %}"

Use the same schema-naming behavior as models

Leverage the generate_schema_name macro to build snapshots in schemas that follow the same naming behavior as your models.

Notes:

  • This macro is not available when configuring from the dbt_project.yml file, so must be configured in a snapshot config block.
  • Consider whether this use-case is right for you, as downstream refs will select from the dev version of a snapshot, which can make it hard to validate models that depend on snapshots (see above FAQ)
snapshots/orders_snapshot.sql
{{
config(
target_schema=generate_schema_name('snapshots')
)
}}
0