From 6f5c9d50d6dc808d1d0421cd23af128d7859b8af Mon Sep 17 00:00:00 2001 From: gfasano <162331471+gfasano@users.noreply.github.com> Date: Thu, 18 Jul 2024 19:34:37 +0200 Subject: [PATCH] Add a sort parameter to star.sql Add a sort paramater that will sort in alphabetical order the return of the column name --- macros/sql/star.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/macros/sql/star.sql b/macros/sql/star.sql index 515b77b6..b068c57c 100644 --- a/macros/sql/star.sql +++ b/macros/sql/star.sql @@ -1,4 +1,4 @@ -{% macro star(from, relation_alias=False, except=[], prefix='', suffix='', quote_identifiers=True) -%} +{% macro star(from, relation_alias=False, except=[], prefix='', suffix='', quote_identifiers=True, sort=False) -%} {{ return(adapter.dispatch('star', 'dbt_utils')(from, relation_alias, except, prefix, suffix, quote_identifiers)) }} {% endmacro %} @@ -26,6 +26,9 @@ dbt compile, and exists to keep SQLFluff happy. */ {% do return("/* no columns returned from star() macro */") %} {% endif %} {%- else -%} + {%- if sort -%} + {% set cols = cols|sort %} + {%- endif -%} {%- for col in cols %} {%- if relation_alias %}{{ relation_alias }}.{% else %}{%- endif -%} {%- if quote_identifiers -%}