Re: Random-looking primary keys in the range 100000..999999 - Mailing list pgsql-general

From Tom Lane
Subject Re: Random-looking primary keys in the range 100000..999999
Date
Msg-id 20745.1404485973@sss.pgh.pa.us
Whole thread Raw
In response to Re: Random-looking primary keys in the range 100000..999999  (Kynn Jones <kynnjo@gmail.com>)
List pgsql-general
Kynn Jones <kynnjo@gmail.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


pgsql-general by date:

Previous
From: Kynn Jones
Date:
Subject: Re: Random-looking primary keys in the range 100000..999999
Next
From: David Wall
Date:
Subject: Re: pg_dump slower than pg_restore