Skip to content

Instantly share code, notes, and snippets.

@arimbr
Created August 15, 2023 20:24
Show Gist options
  • Select an option

  • Save arimbr/b8dc6a37e82a9f84a8e30dbf257a7b7d to your computer and use it in GitHub Desktop.

Select an option

Save arimbr/b8dc6a37e82a9f84a8e30dbf257a7b7d to your computer and use it in GitHub Desktop.
{% macro default__test_relationships(model, column_name, to, field) %}
with child as (
select {{ column_name }} as from_field
from {{ model }}
where {{ column_name }} is not null
),
parent as (
select {{ field }} as to_field
from {{ to }}
)
select
from_field
from child
left join parent
on child.from_field = parent.to_field
where parent.to_field is null
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment