From b4931fe4c5b52739234348098a6bae18f119d198 Mon Sep 17 00:00:00 2001 From: Jay Swanson <37157901+swanjson@users.noreply.github.com> Date: Mon, 13 Jun 2022 15:40:07 -0600 Subject: [PATCH] added: conditional check to see if cols contains columns, if not replace with * (#561) --- macros/sql/star.sql | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/macros/sql/star.sql b/macros/sql/star.sql index 25e58969..e0833275 100644 --- a/macros/sql/star.sql +++ b/macros/sql/star.sql @@ -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 %}