| От | John R Pierce |
|---|---|
| Тема | Re: [Q] string to int hash function for small range |
| Дата | |
| Msg-id | 49B33A2D.4070601@hogranch.com обсуждение исходный текст |
| Ответ на | [Q] string to int hash function for small range ("V S P" <toreason@fastmail.fm>) |
| Ответы |
Re: [Q] string to int hash function for small range
|
| Список | pgsql-general |
V S P wrote:
> I would like to have a function
> given a user id varchar(64) to get a hash number between 0 and 255.
>
> I first tried md5 but the number it returns is very big and cannot
> be converted to an INT
>
> there is likely a way to simply add ascii values of the userId together
> to get a small integer, but wanted to know if there are any other
> 'built-in' ways
>
> this is to get the database id based on user id.
>
maybe take the last byte (2 chars) of the md5, and convert to integer?
something like....
get_byte(decode(md5(id),'hex'),16)
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера