diff --git a/CHANGELOG.md b/CHANGELOG.md index b1861c41..59145411 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ - also ignore `dbt_packages/` directory [#463](https://github.com/dbt-labs/dbt-utils/pull/463) ## Fixes -- `type_timestamp` macro now explicitly casts postgres and redshift warehouse timestamp data types as `timestamp without time zone`, to be consistent with Snowflake behaviour (`timestamp_ntz`). +- `type_timestamp` macro now explicitly casts postgres and redshift warehouse timestamp data types as `timestamp without time zone`, to be consistent with Snowflake behaviour (`timestamp_ntz`). +- `union_relations` macro will now raise an exception if the use of `include` or `exclude` results in no columns ([#473](https://github.com/dbt-labs/dbt-utils/pull/473), [#266](https://github.com/dbt-labs/dbt-utils/issues/266)). + +## Contributors: +- [grahamwetzler](https://github.com/grahamwetzler) (#473) # dbt-utils v0.8.0 ## 🚨 Breaking changes diff --git a/macros/sql/union.sql b/macros/sql/union.sql index 13bafe31..009a765a 100644 --- a/macros/sql/union.sql +++ b/macros/sql/union.sql @@ -61,6 +61,21 @@ {%- set ordered_column_names = column_superset.keys() -%} + {%- if not column_superset.keys() -%} + {%- set relations_string -%} + {%- for relation in relations -%} + {{ relation.name }} + {%- if not loop.last %}, {% endif -%} + {%- endfor -%} + {%- endset -%} + + {%- set error_message -%} + There were no columns found to union for relations {{ relations_string }} + {%- endset -%} + + {{ exceptions.raise_compiler_error(error_message) }} + {%- endif -%} + {%- for relation in relations %} (