Skip to content

Instantly share code, notes, and snippets.

@risicle
Last active June 4, 2024 12:37
Show Gist options
  • Save risicle/36671aaa4bd1be162075058d98a80024 to your computer and use it in GitHub Desktop.
Save risicle/36671aaa4bd1be162075058d98a80024 to your computer and use it in GitHub Desktop.
Rolling-hash aggregator for PostgreSQL, allowing fast exact comparison of columns across tables/databases
CREATE FUNCTION hash_agg_tfunc(bytea, anyelement) RETURNS bytea AS $$
SELECT sha256(convert_to($2::text, 'UTF8') || $1)
$$ LANGUAGE SQL;
CREATE AGGREGATE hash_agg (anyelement) (
sfunc = hash_agg_tfunc,
stype = bytea,
initcond = '{}'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment