Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f3H4uru60121 for ; Tue, 17 Apr 2001 00:56:53 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from hotmail.com (law2-f14.hotmail.com [216.32.181.14]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f3GE02u99623 for ; Mon, 16 Apr 2001 10:00:02 -0400 (EDT) (envelope-from electric_csf@hotmail.com) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 16 Apr 2001 06:59:57 -0700 Received: from 200.214.221.6 by lw2fd.hotmail.msn.com with HTTP; Mon, 16 Apr 2001 13:59:57 GMT X-Originating-IP: [200.214.221.6] From: "Bernardo de Barros Franco" To: peter_e@gmx.net Cc: pgsql-sql@postgresql.org Subject: Re: Using Random Sequence as Key Date: Mon, 16 Apr 2001 10:59:57 -0300 Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Message-ID: X-OriginalArrivalTime: 16 Apr 2001 13:59:57.0960 (UTC) FILETIME=[8583E880:01C0C67D] X-Archive-Number: 200104/259 X-Sequence-Number: 2609 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 Quoting: >Bernardo de Barros Franco writes: > > > 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. > >=> create table test (id int default random() * 89999 + 10000, content >text); >CREATE >=> 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 http://www.hotmail.com.