From: | Martin Gainty <mgainty(at)hotmail(dot)com> |
---|---|
To: | <pierce(at)hogranch(dot)com>, <toreason(at)fastmail(dot)fm> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: [Q] string to int hash function for small range |
Date: | 2009-03-08 03:25:23 |
Message-ID: | BLU142-W442E6BFA3CA222E84DD6BBAEA30@phx.gbl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
or do a mod 256 e.g.
mod(get_byte(md5(id),'hex'),256)
HTH
Martin
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.
> Date: Sat, 7 Mar 2009 19:23:25 -0800
> From: pierce(at)hogranch(dot)com
> To: toreason(at)fastmail(dot)fm
> CC: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] [Q] string to int hash function for small range
>
> 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)
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
_________________________________________________________________
Express your personality in color! Preview and select themes for Hotmail®.
http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=TXT_MSGTX_WL_HM_express_032009#colortheme
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2009-03-08 04:17:19 | Re: [Q] string to int hash function for small range |
Previous Message | John R Pierce | 2009-03-08 03:23:25 | Re: [Q] string to int hash function for small range |