Re: Using Random Sequence as Key - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: Using Random Sequence as Key
Date
Msg-id Pine.LNX.4.30.0104161552540.760-100000@peter.localdomain
Whole thread Raw
In response to Using Random Sequence as Key  ("Bernardo de Barros Franco" <electric_csf@hotmail.com>)
List pgsql-sql
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 | hi72605 | there83469 | blah
(3 rows)

Verifying the default expression for correct boundaries is left as an
exercise.  ;-)

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter



pgsql-sql by date:

Previous
From: "Bernardo de Barros Franco"
Date:
Subject: Using Random Sequence as Key
Next
From: Jeff Hoffmann
Date:
Subject: Re: RTREE on points