为处理大数据量的表格,识别不同时间段对表格实现的更改,先将两张同结构表的不同数据记录提取出来,存为单独的结果表,方便后续的区别到底来自于那个字段的识别。
create or replace function get_tables_differences
(in schema_n_1 text,in schema_n_2 text,in table_n_1 text,in table_n_2 text)
returns void
language plpgsql
as $$
begin
drop table if exists temp_table_1;
drop table if exists temp_table_2;
drop table if exists result_table_get_tables_differences;
execute format('create table temp_table_1 as select * from %I.%I limit(0)',schema_n_1,table_n_1);
execute format('create table temp_table_2 as select * from %I.%I limit(0)',schema_n_2,table_n_2);
alter table temp_table_1 add column if not exists from_where text default 'first_table';
alter table temp_table_2 add column if not exists from_where text default 'second_table';
execute format('insert into temp_table_1 (select * from %I.%I except select * from %I.%I)',schema_n_1,table_n_1,schema_n_2,table_n_2