[GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Joe Kramer
Hello, I need to generate unique id which is not guessable unlike serial(integer) type. I need an id in format like md5 hash of random number. On top of that I need this id to be unique across multiple tables. Anyone had to solve this problem before? Can you post any recipes or best practices

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Adrian von Bidder
Hi, On Friday 29 January 2010 09.20:33 Joe Kramer wrote: I need to generate unique id which is not guessable unlike serial(integer) type. I need an id in format like md5 hash of random number. On top of that I need this id to be unique across multiple tables. Have a look at

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Magnus Hagander
On Fri, Jan 29, 2010 at 10:31, Adrian von Bidder avbid...@fortytwo.ch wrote: Hi, On Friday 29 January 2010 09.20:33 Joe Kramer wrote: I need to generate unique id which is not guessable unlike serial(integer) type. I need an id in format like md5 hash of random number. On top of that I

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Joe Kramer
We have bunch of servers running the app and rebuilding postgres with support for ossp_uuid on all servers is time consuming. Is there a way of doing it without third party dependency like ossp_uuid? Should I just run md5(random number), will itbe the same ?. According to description it seems that

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Adrian von Bidder
On Friday 29 January 2010 11.21:00 Joe Kramer wrote: We have bunch of servers running the app and rebuilding postgres with support for ossp_uuid on all servers is time consuming. Is there a way of doing it without third party dependency like ossp_uuid? Should I just run md5(random number),

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread hubert depesz lubaczewski
On Fri, Jan 29, 2010 at 07:20:33PM +1100, Joe Kramer wrote: I need to generate unique id which is not guessable unlike serial(integer) type. I need an id in format like md5 hash of random number. check this blogpost: http://www.depesz.com/index.php/2007/06/25/random-text-record-identifiers/

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Joe Kramer
Thanks for the answer, I am unable to use ossp_uuid due to package install and/or server rebuild requirement. So I am trying to roll my own, and digest(quote_literal(random()+random()), 'sha256'), 'hex') doesn't work: I have created this table and inserted 20 rows (two million). This is

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Adrian von Bidder
On Friday 29 January 2010 12.51:20 Joe Kramer wrote: So this means random()+random() is not random even within 2,000,000 iterations! Exactly the issue I wrote about: random() apparently doesn't deliver enough randomness. Even if it did: quote_literal(random() + random()) is ca. 14 to 16

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Wappler, Robert
On 2010-01-29, Joe Kramer wrote: Thanks for the answer, I am unable to use ossp_uuid due to package install and/or server rebuild requirement. So I am trying to roll my own, and digest(quote_literal(random()+random()), 'sha256'), 'hex') doesn't work: Your input value is a random

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Ivan Sergio Borgonovo
On Fri, 29 Jan 2010 13:13:17 +0100 Wappler, Robert rwapp...@ophardt.com wrote: I'd suggest to use some kind of sequence or something constructed from the primary keys. But you may still see hash collisions although the input is different. Concatenate /* ::text */ random() with something like:

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Craig Ringer
On 29/01/2010 4:20 PM, Joe Kramer wrote: Hello, I need to generate unique id which is not guessable unlike serial(integer) type. I need an id in format like md5 hash of random number. On top of that I need this id to be unique across multiple tables. Anyone had to solve this problem before?

Re: [GENERAL] How to generate unique hash-type id?

2010-01-29 Thread Joe Kramer
Thanks for that link Depesz! It worked, I've run ALTER TABLE with your function and didn't have collisions. I guess it's more bulletproof because random() is called not once, but for every character therefore reducing possibility of collision by multitude of number of bytes in hash. CREATE OR