database
- Model
- Seeds
- Snapshots
- Tests
Specify a custom database for a model in your dbt_project.yml
file.
For example, if you have a model that you want to load into a database other than the target database, you can configure it like this:
models:
your_project:
sales_metrics:
+database: reporting
This would result in the generated relation being located in the reporting
database, so the full relation name would be reporting.finance.sales_metrics
instead of the default target database.
Configure a database in your dbt_project.yml
file.
For example, to load a seed into a database called staging
instead of the target database, you can configure it like this:
seeds:
your_project:
product_categories:
+database: staging
This would result in the generated relation being located in the staging
database, so the full relation name would be staging.finance.product_categories
.
Specify a custom database for a snapshot in your dbt_project.yml
or config file.
For example, if you have a snapshot that you want to load into a database other than the target database, you can configure it like this:
snapshots:
your_project:
your_snapshot:
+database: snapshots
This results in the generated relation being located in the snapshots
database so the full relation name would be snapshots.finance.your_snapshot
instead of the default target database.
Configure a database in your dbt_project.yml
file.
For example, to load a test into a database called reporting
instead of the target database, you can configure it like this:
tests:
- my_not_null_test:
column_name: order_id
type: not_null
+database: reporting
This would result in the generated relation being located in the reporting
database, so the full relation name would be reporting.finance.my_not_null_test
.
Definition
Optionally specify a custom database for a model, seed, or data test. (To specify a database for a snapshot, use the target_database
config).
When dbt creates a relation (tableIn simplest terms, a table is the direct storage of data in rows and columns. Think excel sheet with raw values in each of the cells./viewA view (as opposed to a table) is a defined passthrough SQL query that can be run against a database (or data warehouse).) in a database, it creates it as: {{ database }}.{{ schema }}.{{ identifier }}
, e.g. analytics.finance.payments
The standard behavior of dbt is:
- If a custom database is not specified, the database of the relation is the target database (
{{ target.database }}
). - If a custom database is specified, the database of the relation is the
{{ database }}
value.
To learn more about changing the way that dbt generates a relation's database
, read Using Custom Databases
Warehouse specific information
- BigQuery:
project
anddatabase
are interchangeable