Re: Is a randomized default value primary key - Mailing list pgsql-novice

From ghaverla@freenet.edmonton.ab.ca
Subject Re: Is a randomized default value primary key
Date
Msg-id Pine.A41.3.95.1020519163610.24448B-100000@fn2.freenet.edmonton.ab.ca
Whole thread Raw
In response to Re: Is a randomized default value primary key  ("Joel Burton" <joel@joelburton.com>)
List pgsql-novice
On Sun, 19 May 2002, Joel Burton wrote:

> > I made the primary key
> >
> > "authkey"    bigint DEFAULT trunc(random()*10^15) NOT NULL

> Be sure to build into your app some way of handling the error that will
> happen if a random primary key is already in the table -- resubmitting it
> should work fine (the odds of this happening twice become _extremely_
> unlikely, unless your table is very large)

If you know about how many rows you will be inserting, why not
build a table of random ints drawn from a finite pool without
replacement?  Then, you just have to pick the next unused random
int from the random pool table to use in your other table.  If
you get to the point where the table is exhausted (surely the
number of rows in the pool is less than the period), you just
add some more random ints.

> Anyone know off the top of their heads what the period for PG's random()
> function is?

Sorry, not I.

Gord

Matter Realisations     http://www.materialisations.com/
Gordon Haverland, B.Sc. M.Eng. President
101  9504 182 St. NW    Edmonton, AB, CA  T5T 3A7
780/481-8019            ghaverla @ freenet.edmonton.ab.ca
780/993-1274 (cell)



pgsql-novice by date:

Previous
From: "Joel Burton"
Date:
Subject: Re: Is a randomized default value primary key
Next
From: Josh Berkus
Date:
Subject: Re: Is a randomized default value primary key