consistent hashing - Is there a way to generate hash integer within a predefined range for a string in PostgreSQL? -
consistent hashing - Is there a way to generate hash integer within a predefined range for a string in PostgreSQL? -
for sharding need hash algorithm. need generate hash integer value string within 0-2^31 range. possible ?
following reply give way generate integer md5 algorithm.
hashing string numeric value in postgressql
but there way generate value within range ?
in function suggested in hashing string numeric value in postgressql, 32 bits range expressed width of bit(n)
cast.
it cannot passed parameter because type modifier must constant, fixed 31 bits, may adjust function this:
create function hash_string_into_31_bits(text) returns int $$ select ('x'||substr(md5($1),1,8))::bit(31)::int; $$ language sql;
then result 31 bits wide , positive, same thing.
postgresql consistent-hashing
Comments
Post a Comment