From: Bernardo de Barros Franco <electric_csf@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Using Random Sequence as Key
Date: Mon, 16 Apr 2001 17:03:18 -0300
Message-ID: <9bfiro$qma$1@news.tht.net> (raw)
References: <20010416103149.A17607@cc.usu.edu>
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.
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: electric_csf@hotmail.com
Subject: Re: Using Random Sequence as Key
In-Reply-To: <9bfiro$qma$1@news.tht.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox