Re: Is a randomized default value primary key

From: ghaverla(at)freenet(dot)edmonton(dot)ab(dot)ca
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Is a randomized default value primary key
Date: 2002-05-19 22:40:36
Message-ID: Pine.A41.3.95.1020519163610.24448B-100000@fn2.freenet.edmonton.ab.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2002-05-19 22:58:03 Re: Is a randomized default value primary key
Previous Message Joel Burton 2002-05-19 22:29:21 Re: Is a randomized default value primary key