Hash Table in 20 Lines

Follow @aquameta
-- hash table

create extension if not exists pgcrypto schema public;

create table blob (  
    hash bytea unique,
    value text
);

create function blob_hash_gen_trigger() returns trigger as $$  
    begin
        NEW.hash = public.digest(NEW.value, 'sha256');
        return NEW;
    end;
$$ language plpgsql;

create trigger blob_hash_update  
    before insert or update on blob
    for each row execute procedure blob_hash_gen_trigger();

Comments

comments powered by Disqus