From 60e57205a51c4512fa756bd028c7bd15ca3a1182 Mon Sep 17 00:00:00 2001 From: swanjson Date: Tue, 26 Apr 2022 19:54:22 -0600 Subject: [PATCH] added: conditional check to see if cols contains columns, if not replace with * --- 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 %}