+++ /dev/null
-create function zz_concat(bytea, bytea) returns bytea as
- $$select digest($1 || $2,'sha256');$$ strict language 'sql';
-
-create aggregate zz_hashagg(bytea) (
- sfunc = zz_concat,
- stype = bytea
-);
-
-create function table_hash(t regclass, key text) returns text
-language plpgsql as $$
-declare
- tval bytea;
- sql text;
-begin
- sql := 'select zz_hashagg(digest(t::text, ''sha256'') order by '
- || quote_ident(key)
- || ') from ' || t || ' t ';
- execute sql into tval;
- return encode(tval, 'hex');
-end;
-$$;
-
-create function table_hash(t regclass, key text, firstn bigint) returns text
-language plpgsql as $$
-declare
- tval bytea;
- sql text;
-begin
- sql := 'select zz_hashagg(digest(t::text, ''sha256'') order by '
- || quote_ident(key)
- || ') from ('
- || 'select * from ' || t || ' order by ' || quote_ident(key)
- || ' limit ' || firstn
- || ') t';
-
- execute sql into tval;
- return encode(tval, 'hex');
-end;
-$$;
-
-/*
-create function all_hash() returns text language plpgsql as $$
-declare
- tval text;
- sql text;
-begin
- select migration.zz_hashagg(migration.table_hash(C.oid) order by C.relname) into tval
- from pg_attribute A
- join pg_class C on C.oid = A.attrelid
- where
- A.attname = '_migration_id'
- and C.relkind = 'r'
- ;
-
- return tval;
-end;
-$$;
-*/
-
-begin;
-
create function zz_concat(bytea, bytea) returns bytea as
$$select digest($1 || $2,'sha256');$$ strict language 'sql';
return encode(tval, 'hex');
end;
$$;
-
-\timing
-select table_hash('history.t_archivenotamserachfromns_20140328'::regclass, 10000);
---select table_hash('bar'::regclass, 'b', 100);
-
-rollback;
-
-/*
-create function all_hash() returns text language plpgsql as $$
-declare
- tval text;
- sql text;
-begin
- select migration.zz_hashagg(migration.table_hash(C.oid) order by C.relname) into tval
- from pg_attribute A
- join pg_class C on C.oid = A.attrelid
- where
- A.attname = '_migration_id'
- and C.relkind = 'r'
- ;
-
- return tval;
-end;
-$$;
-*/
-