Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f3H4xTu60545 for ; Tue, 17 Apr 2001 00:59:29 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f3GKPPu81969 for ; Mon, 16 Apr 2001 16:25:25 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.1/8.11.1) id f3GJvlb27341 for pgsql-sql@postgresql.org; Mon, 16 Apr 2001 15:57:47 -0400 (EDT) (envelope-from news) From: "Bernardo de Barros Franco" X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Using Random Sequence as Key Date: Mon, 16 Apr 2001 17:03:18 -0300 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 32 Message-ID: <9bfiro$qma$1@news.tht.net> References: <20010416103149.A17607@cc.usu.edu> X-Complaints-To: scrappy@hub.org X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 To: pgsql-sql@postgresql.org X-Archive-Number: 200104/260 X-Sequence-Number: 2610 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. >