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

Re: Using Random Sequence as Key

From: "Bernardo de Barros Franco" <electric_csf(at)hotmail(dot)com>
To: peter_e(at)gmx(dot)net
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using Random Sequence as Key
Date: 2001-04-16 13:59:57
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Thank you it was pretty much something like that. I need to make a sale 
table but the sale code is a random number. Since it is going to be used in 
all queries and it is unique, it might as well be my table key (index). I 
could make a index and other field to be the sale code but then I would have 
2 different indexes, the table index and the sale code that would be used 
for all queries.
But my only question would be, in the example quoted would id be really the 
table index and is it unique?

Thank you

>Bernardo de Barros Franco writes:
> > I wanted to index a table by a random key. Exemplifying, when a insert 
> > made, the id value is automatically filled with a random number between
> > 10000 and 99999.
>=> create table test (id int default random() * 89999 + 10000, content 
>=> insert into test (content) values ('hi');
>INSERT 36163 1
>=> insert into test (content) values ('there');
>INSERT 36164 1
>=> insert into test (content) values ('blah');
>INSERT 36165 1
>=> select * from test;
>   id   | content
>  61616 | hi
>  72605 | there
>  83469 | blah
>(3 rows)
Get Your Private, Free E-mail from MSN Hotmail at


pgsql-sql by date

Next:From: Peter EisentrautDate: 2001-04-16 14:03:54
Subject: Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff
Previous:From: Peter EisentrautDate: 2001-04-16 13:55:46
Subject: Re: Using Random Sequence as Key

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