From: D'Arcy J.M. Cain <darcy@druid.net>
To: A. Kretschmer <andreas.kretschmer@schollglas.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Create on insert a unique random number
Date: Tue, 18 Mar 2008 13:38:24 -0400
Message-ID: <20080318133824.4f35957b.darcy@druid.net> (raw)
In-Reply-To: <20080318165138.GA6578@a-kretschmer.de>
References: <B10E6810AC2A2F4EA7550D072CDE8760CDDC32@SAB-FENWICK.sab.uiuc.edu>
<268179.51357.qm@web54301.mail.re2.yahoo.com>
<20080318165138.GA6578@a-kretschmer.de>
On Tue, 18 Mar 2008 17:51:39 +0100
"A. Kretschmer" <andreas.kretschmer@schollglas.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@druid.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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: darcy@druid.net, andreas.kretschmer@schollglas.com
Subject: Re: Create on insert a unique random number
In-Reply-To: <20080318133824.4f35957b.darcy@druid.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox