From: | Magnus Hagander <magnus(at)hagander(dot)net> |
---|---|
To: | Adrian von Bidder <avbidder(at)fortytwo(dot)ch> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: How to generate unique hash-type id? |
Date: | 2010-01-29 09:41:12 |
Message-ID: | 9837222c1001290141n7ab8e44emb7e721f972d41d71@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Jan 29, 2010 at 10:31, Adrian von Bidder <avbidder(at)fortytwo(dot)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 need this id to be unique across multiple tables.
>
> Have a look at http://www.postgresql.org/docs/8.3/static/uuid-ossp.html
>
> The usual approach is that (given a sensible random generator[1]) uuid are
> assumed to be unique[2]. So you don't need to check because the probability
> of collisions is so small that for practical purposes you can just ignore
> it.
>
> (If your engineer's mind balks at this, consider that you're trusting this
> already when you use digital cryptography / signatures, for example https
> certificates.)
uuid:s are, AFAIK, not cryptographically strong. They are predictable
- a lot less predictable than a sequence, but still. If you want
secure random numbers, you need to look at pgcrypto -
http://www.postgresql.org/docs/current/static/pgcrypto.html
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
From | Date | Subject | |
---|---|---|---|
Next Message | 沈雷 | 2010-01-29 09:45:08 | Re: Output float number with hex format |
Previous Message | Adrian von Bidder | 2010-01-29 09:31:44 | Re: How to generate unique hash-type id? |