Re: Is a randomized default value primary key possible?

From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: PgSQL Novice ML <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Is a randomized default value primary key possible?
Date: 2002-05-19 20:10:30
Message-ID: 1021839030.9171.42.camel@rebel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Sun, 2002-05-19 at 11:10, April L wrote:
> After reading about data types, create table, and other search results for
> "default" and "random" in the postgres idocs, I haven't found a way to do
> this:
>
> Instead of a sequentially auto-incrementing primary key, I would like a
> random 16 byte character value (assumedly hex) to be automatically created
> as the default value for each new record.
>
> I guess I could just use a large random number, created with the postgres
> random() function - however I don't see any way of seeding it, or know if
> that is necessary.
>
> The purpose of using a random rather than sequential number is to prevent
> people being able to access other's records by guessing.
>
> Has anyone else encountered this challenge, and do you know of a way to
> generate a random default value for the primary key?

Have you considered appending (or prepending) a check digit
to the sequence number before inserting into the database?

That way, it is unlikely someone will get an account just by
typing in a random number. Also, and more importantly, it will
ensure that any fat-fingers by the clerical staff doesn't
accidently bring up the wrong account.

--
+---------------------------------------------------------+
| Ron Johnson, Jr. Home: ron(dot)l(dot)johnson(at)cox(dot)net |
| Jefferson, LA USA http://ronandheather.dhs.org:81 |
| |
| "I have created a government of whirled peas..." |
| Maharishi Mahesh Yogi, 12-May-2002, |
! CNN, Larry King Live |
+---------------------------------------------------------+

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2002-05-19 20:49:31 Re: Is a randomized default value primary key possible?
Previous Message Josh Berkus 2002-05-19 18:59:57 Re: Forgotten the master password of db