Skip to content

Instantly share code, notes, and snippets.

@yoshiokatsuneo
Created January 31, 2025 01:57
Show Gist options
  • Save yoshiokatsuneo/84c8a490d27f4d5d60cc78153e3f0b8c to your computer and use it in GitHub Desktop.
Save yoshiokatsuneo/84c8a490d27f4d5d60cc78153e3f0b8c to your computer and use it in GitHub Desktop.
create or replace procedure yoshioka_test1.assert_table_count_equal(table_name1 string, table_name2 string)
begin
execute immediate '''
with
results as (
select
(select count(*) from ''' || table_name1 || ''') as expected,
(select count(*) from ''' || table_name2 || ''') as actual,
)
select * from results
where
if(expected = actual, true, error('Not equal row counts. ''' || table_name1 || ''': ' || expected || ' rows. ''' || table_name2 || ''': ' || actual || ' rows.'))
''';
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment