Ajmal Moideen
Ajmal Moideen

Reputation: 230

DBT - Override name of the model. Two models with same table name?

There are two sources, each of them has a patient table that gets shipped

I use dbt to transform the sources to snowflake tables. Now, I want to use the same table as source1.schema.patient and source2.schema.patient correspondingly.

However, when I use dbt to build the models, it throws an error saying cannot use same model names for two .sql files. Since, I use source1 name already in the name of the database, I do not want to use it again in the name of the table.

dbt --version
Core:
  - installed: 1.5.6
  - latest:    1.6.4 - Update available!

  Your version of dbt-core is out of date!
  You can find instructions for upgrading here:
  https://docs.getdbt.com/docs/installation

Plugins:
  - snowflake: 1.5.2 - Update available!

  At least one plugin is out of date or incompatible with dbt-core.
  You can find instructions for upgrading here:
  https://docs.getdbt.com/docs/installation

I have two schema files for each of this sources in separate folders. Each having a reference to patient

Upvotes: 1

Views: 2627

Answers (1)

Koushik Roy
Koushik Roy

Reputation: 7397

There is no straight way to do this. However you can do below workaround -

1.Rename the sql files so that it can be unique.

  • model.folder.mymodel_schema1.sql
  • model.folder.mymodel_schema2.sql

2.added 'ALIAS' parameter tag in the sql file like below - mymodel_schema1.sql

{{ config(materialized=‘table’, alias=‘mymodel’, schema='SCHEMA1') }}

mymodel_schema2.sql

{{ config(materialized=‘table’, alias=‘mymodel’, schema='SCHEMA2') }}

Upvotes: 1

Related Questions