Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id E53D12E01A0 for ; Tue, 18 Mar 2008 14:38:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 05877-03 for ; Tue, 18 Mar 2008 14:38:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smaug.vex.net (smaug.vex.net [208.76.104.132]) by postgresql.org (Postfix) with ESMTP id 418BA2E0180 for ; Tue, 18 Mar 2008 14:38:27 -0300 (ADT) Received: from dilbert (dilbert.druid.net [207.35.13.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smaug.vex.net (Postfix) with ESMTP id C8FE517FF6; Tue, 18 Mar 2008 13:38:24 -0400 (EDT) Date: Tue, 18 Mar 2008 13:38:24 -0400 From: "D'Arcy J.M. Cain" To: "A. Kretschmer" Cc: pgsql-sql@postgresql.org Subject: Re: Create on insert a unique random number Message-Id: <20080318133824.4f35957b.darcy@druid.net> In-Reply-To: <20080318165138.GA6578@a-kretschmer.de> References: <268179.51357.qm@web54301.mail.re2.yahoo.com> <20080318165138.GA6578@a-kretschmer.de> X-Mailer: Sylpheed 2.4.8 (GTK+ 2.12.8; x86_64--netbsd) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/105 X-Sequence-Number: 30433 On Tue, 18 Mar 2008 17:51:39 +0100 "A. Kretschmer" 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 | 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.