The problem
I am using a macro which uses a variable to create a source name. Instead of taking the variable passed in the command line, the default variable from dbt_project.yml is being used.
The context of why I’m trying to do this
dbt core 1.4.9. (cannot have the newest version because of conflict with dbt-sqlserver package,run both in terminal and in PyCharm terminal with the same output
Example code
Variable definition in dbt_project.yml:
profile: 'myprofile'
vars:
market: 'hu'
Macro looks like;
{% macro db_source_var(source_name, table_name) %}
{% set dataset_name = var('market') %}
{{ source(source_name + "_" + dataset_name, table_name)}}
{% endmacro %}
Exampe command:
dbt run --target=beta --vars '{market:sk}'
My profile looks like:
myprofile:
target: cz
outputs:
cz:
type: sqlserver
driver: 'ODBC Driver 17 for SQL Server'
server: BETA
port: 1433
database: XXX
schema: cz
windows_login: True
trust_cert: True
threads: 4
sk:
type: sqlserver
driver: 'ODBC Driver 17 for SQL Server'
server: BETA
port: 1433
database: YYY
schema: sk
windows_login: True
trust_cert: True
threads: 4
hu:
type: sqlserver
driver: 'ODBC Driver 17 for SQL Server'
server: BETA
port: 1433
database: ZZZ
schema: hu
windows_login: True
trust_cert: True
threads: 4
beta:
type: sqlserver
driver: 'ODBC Driver 17 for SQL Server'
server: BETA
port: 1433
database: BBB
schema: beta
windows_login: True
trust_cert: True
threads: 4