Derek C
Derek C

Reputation: 31

Anyway to apply column quoting to all columns in a model

I am using DBT with snowflake as my target and the table and column names are Pascal Cased. I've noticed that in both persist_docs or when adding tests you need to add the quote: true attribute to every column like in the model example below.

if the quote: true is not provided or the name isn't encased in single then double quotes (ex. ColumnName) then DBT doesn't quote the column when creating the sql for test or the alter column for comment statements.

Is there any setting that can be done at the model level or above that will quote all columns by default or do I just have to set quote: true for all columns?

models:
    - name: tablename
      description: '....' 
      columns: 
          - name: ColumnName
            quote: true
            description: '{{ doc("ColumnName") }}'

Upvotes: 3

Views: 2314

Answers (1)

Julian Eccleshall
Julian Eccleshall

Reputation: 564

I am having the same demand but can not fund a solution yet. my workaround is defined a macro to call dbt_utils.star then do this:

{% for col in dbt_utils.star(table_relation, exclued_cols) %}
     {% do columns_list.append('"' ~ col ~ '"') %}
{% endfor %}
return (columns_list)

you can call that macro to put the quote on all your column.

Upvotes: 0

Related Questions