From 53703b90b5ee16e6ac5ab8797824a09cedb64f70 Mon Sep 17 00:00:00 2001 From: Martin Jung Date: Thu, 7 Sep 2023 23:19:10 +1000 Subject: [PATCH] Output '*' in union_relations when no columns are found in compile mode This is to handle the scenario where the upstream relations haven't been run, and you run SQLFluff against a model using union_relations, with source_column_name=None. --- macros/sql/union.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/macros/sql/union.sql b/macros/sql/union.sql index ac289e2f..0d1f8961 100644 --- a/macros/sql/union.sql +++ b/macros/sql/union.sql @@ -103,6 +103,12 @@ cast({{ dbt.string_literal(relation) }} as {{ dbt.type_string() }}) as {{ source_column_name }}, {%- endif %} + /* No columns from any of the relations. + This star is only output during dbt compile, and exists to keep SQLFluff happy. */ + {% if dbt_command == 'compile' and ordered_column_names|length == 0 %} + * + {% endif %} + {% for col_name in ordered_column_names -%} {%- set col = column_superset[col_name] %}