Skip to content

Commit

Permalink
added: conditional check to see if cols contains columns, if not repl…
Browse files Browse the repository at this point in the history
…ace with * (#561)
  • Loading branch information
swanjson authored Jun 13, 2022
1 parent 67ef54b commit b4931fe
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions macros/sql/star.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
{{ return('*') }}
{% endif %}

{%- for col in dbt_utils.get_filtered_columns_in_relation(from, except) %}
{% set cols = dbt_utils.get_filtered_columns_in_relation(from, except) %}

{%- if relation_alias %}{{ relation_alias }}.{% else %}{%- endif -%}{{ adapter.quote(col)|trim }} {%- if prefix!='' or suffix!='' %} as {{ adapter.quote(prefix ~ col ~ suffix)|trim }} {%- endif -%}
{%- if not loop.last %},{{ '\n ' }}{% endif %}

{%- endfor -%}
{%- if cols|length <= 0 -%}
{{- return('*') -}}
{%- else -%}
{%- for col in cols %}
{%- if relation_alias %}{{ relation_alias }}.{% else %}{%- endif -%}{{ adapter.quote(col)|trim }} {%- if prefix!='' or suffix!='' %} as {{ adapter.quote(prefix ~ col ~ suffix)|trim }} {%- endif -%}
{%- if not loop.last %},{{ '\n ' }}{% endif %}
{%- endfor -%}
{% endif %}
{%- endmacro %}

0 comments on commit b4931fe

Please sign in to comment.