schema name is not correct

We are running a model (eg: dbt run -m sales.sql" ) having schema defined at properties.yml, , say it is mdel_schema. And profile too has the schema defined, say it is prof_schema.

When the job runs, sales view is created with schema name as prof_schema_mdel_schema. Schema name in the model is not getting overwritten, however it appends the names from profile and property.

Is there any option available to use the property schema alone?

Try using dbt run -s sales instead of dbt run -m sales.sql

Hi

Hi @GaneshSubramani,

You can override the default generate_schema_name macro

So, instead of using the macro like this

{% macro generate_schema_name(custom_schema_name, node) -%}

    {%- set default_schema = target.schema -%}
    {%- if custom_schema_name is none -%}

        {{ default_schema }}

    {%- else -%}

        {{ default_schema }}_{{ custom_schema_name | trim }}

    {%- endif -%}

{%- endmacro %}

You can create your own macro like this

{% macro generate_schema_name(custom_schema_name, node) -%}

    {%- set default_schema = target.schema -%}
    {%- if custom_schema_name is none -%}

        {{ default_schema }}

    {%- else -%}

        {{ custom_schema_name | trim }}

    {%- endif -%}

{%- endmacro %}
1 Like

Thanks for the help, this worked as expected.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.