Skip site navigation (1) Skip section navigation (2)

Re: Is a randomized default value primary key

From: "Joel Burton" <joel(at)joelburton(dot)com>
To: "April L" <april(at)i-netco(dot)com>,"PgSQL Novice ML" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Is a randomized default value primary key
Date: 2002-05-19 22:29:21
Message-ID: JGEPJNMCKODMDHGOBKDNOEMECOAA.joel@joelburton.com (view raw or flat)
Thread:
Lists: pgsql-novice
> I made the primary key
>
> "authkey"	bigint DEFAULT trunc(random()*10^15) NOT NULL
>
> Does that seem reasonable? bigint is 8 bytes. I came up with this prior to
> receiving your reply.
>
> Since I do have to use the authkey to find records, it seems I would still
> benefit by having an index for it even if I had a separate 4 byte primary
> key - so I don't understand how it would save resources or increase
> performance to avoid making this column the primary key? Admittedly, I
> don't understand indexes in depth yet, I just assumed that every
> additional
> index means additional housekeeping activities each time a record is
> changed or added.
>
> Thank you,
>
> - April

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)

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

- J.



In response to

Responses

pgsql-novice by date

Next:From: ghaverlaDate: 2002-05-19 22:40:36
Subject: Re: Is a randomized default value primary key
Previous:From: April LDate: 2002-05-19 22:19:36
Subject: Re: Is a randomized default value primary key

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group