From: | "Bernardo de Barros Franco" <electric_csf(at)hotmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Using Random Sequence as Key |
Date: | 2001-04-16 20:03:18 |
Message-ID: | 9bfiro$qma$1@news.tht.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Since I can't really redesign my application, I could index the table using
a serial but still would need a field with the random and unique number. I
tried using including a unique in : create table test (id int UNIQUE default
random() * 89999 + 10000, content text); and it didn't return any errors,
I'm just not sure if it actually worked.
I needed the random field because if I use serial and the user gets a 34203
he's sure that 34202 exists, and that (probably, there where 34202 inserts
before him (or at least an offset + some)). Using a random just makes the
user totally blind.
As I said I could use a serial for indexing the table but I NEED the random
field and I need to to be unique since all the queries will be using it as a
search parameter.
If inserting this way is slow it's not such a big deal since it's a small db
and inserts are seldom made.
Thanks in advance for any help.
Quoting:
> On Sun, Apr 15, 2001 at 10:58:40PM -0300, Bernardo de Barros Franco wrote:
>
> > I wanted to index a table by a random key. Exemplifying, when a insert
is
> > made, the id value is automatically filled with a random number between
> > 10000 and 99999. I'm pretty new in pgsql so I could use a howto or
>
> Bernardo,
>
> Do you really need the keys to be random numbers? Can't the keys be
> sequential numbers, like 1,2,3,4...? That'd be a lot easier to make
> unique, and as far as the user is concerned, it'll be random for him/her.
>
From | Date | Subject | |
---|---|---|---|
Next Message | Dan Lyke | 2001-04-16 20:16:29 | Using Random Sequence as Key |
Previous Message | cbell | 2001-04-16 17:48:03 | Re: Range of Serial values |