Skip to content

Commit

Permalink
Output '*' in union_relations when no columns are found in compile mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinshjung committed Jul 2, 2024
1 parent 4da44cb commit 53703b9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions macros/sql/union.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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] %}
Expand Down

0 comments on commit 53703b9

Please sign in to comment.