I have two nested tables one is source and another is target table. I wanted to compare nested columns of source and target table. I am comparing two tables to check weather data is being updated in source table or not. Is there any sql in BigQuery to achieve the same?
Here are my approaches which I was previously doing to compare two tables with nested record:
1. This is the first approach:
SELECT to_json_string(info) FROM database.nested_table_source
except distinct
SELECT to_json_string(info) FROM nested_table_target
to_json_string() is not working, since this function returns different sequence of source rows and target rows sometimes, even though data is same in both tables, it results out different records.
2. This is the second approach:
select name
from dataset.nested_table_source a
join dataset.nested_table_target b
using(name)
where
a.name!=b.name and
(select string_agg(format('%t', s) order by key) from a.info s)
!= (select string_agg(format('%t', s) order by key ) from b.info s)
In this approach I am using string_agg function to compare two nested records. But I am not sure if that is the correct way to compare record fields.
What should I do in this case?
