Re: Create on insert a unique random number

From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Create on insert a unique random number
Date: 2008-03-18 17:38:24
Message-ID: 20080318133824.4f35957b.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, 18 Mar 2008 17:51:39 +0100
"A. Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> wrote:
> am Tue, dem 18.03.2008, um 9:43:01 -0700 mailte chester c young folgendes:
> > > When inserting a record is there a way to have postgres create a
> > > random number for a field such that it is unique?
> >
> > you could use oid
>
> No! No oid, it's deprecated. The solution: use serial.

Not exactly random, is it?

See http://archives.postgresql.org/pgsql-novice/2002-05/msg00198.php
for a possible solution. Read the followups as well. There is an
issue with collisions which will only get worse with time.

I wonder though, what is the purpose of this? I suspect that this is
either a homework problem or you may be attacking some real-world
problem from the wrong angle.

--
D'Arcy J.M. Cain <darcy(at)druid(dot)net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Vivek Khera 2008-03-18 17:56:37 Re: Create on insert a unique random number
Previous Message paul rivers 2008-03-18 17:33:29 Re: Create on insert a unique random number