Re: Random-looking primary keys in the range 100000..999999

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kynn Jones <kynnjo(at)gmail(dot)com>
Cc: hubert depesz lubaczewski <depesz(at)gmail(dot)com>, pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Random-looking primary keys in the range 100000..999999
Date: 2014-07-04 14:59:33
Message-ID: 20745.1404485973@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Kynn Jones <kynnjo(at)gmail(dot)com> writes:
> The requirements I've been given for the keys is that they be numeric,
> reasonably easy to type (hence, no 40-digit keys), never beginning with 0,
> and carrying no additional information content (or even suggesting it).

Why not just

(random()*899999)::int + 100000

This is unlikely to be cryptographically secure, but you didn't say you
needed that. You will need to check for collisions, but that seems like
something you really ought to do anyway.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Wall 2014-07-04 15:55:08 Re: pg_dump slower than pg_restore
Previous Message Kynn Jones 2014-07-04 14:49:29 Re: Random-looking primary keys in the range 100000..999999