Skip to content

Instantly share code, notes, and snippets.

@danbst
danbst / uuid-bloom.sql
Created April 27, 2019 10:40
Postgresql UUID Bloom index support (best for UUIDv4) (https://www.postgresql.org/docs/current/bloom.html)
create extension "uuid-ossp";
-- https://www.postgresql.org/docs/current/bloom.html
create extension bloom;
CREATE or replace FUNCTION hashuuid(u uuid) RETURNS integer AS $$
DECLARE
a bytea := uuid_send(u);
BEGIN
RETURN (get_byte(a, 3) << 24) + (get_byte(a, 2) << 16) + (get_byte(a, 1) << 8) + get_byte(a, 0);
END;