Skip to content

Commit

Permalink
ensure that values are present (or null) in both tables before counti…
Browse files Browse the repository at this point in the history
…ng them as conflicting
  • Loading branch information
leoebfolsom committed Mar 27, 2023
1 parent 49d3479 commit 1dbaaf9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions macros/compare_column_values_verbose.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ b_query as (
a_query.{{ primary_key }} is null as missing_from_a,
b_query.{{ primary_key }} is null as missing_from_b,
coalesce(
a_query.{{ column_to_compare }} != b_query.{{ column_to_compare }} or
(a_query.{{ column_to_compare }} is not null and b_query.{{ column_to_compare }} is null) or
(a_query.{{ column_to_compare }} is null and b_query.{{ column_to_compare }} is not null),
a_query.{{ primary_key }} is not null and b_query.{{ primary_key }} is not null and
-- ensure that neither value is missing before considering it a conflict
(
a_query.{{ column_to_compare }} != b_query.{{ column_to_compare }} or -- two not-null values that do not match
(a_query.{{ column_to_compare }} is not null and b_query.{{ column_to_compare }} is null) or -- null in b and not null in a
(a_query.{{ column_to_compare }} is null and b_query.{{ column_to_compare }} is not null) -- null in a and not null in b
),
false
) as conflicting_values
-- considered a conflict if the values do not match AND at least one of the values is not null.
Expand Down

0 comments on commit 1dbaaf9

Please sign in to comment.