Skip site navigation (1) Skip section navigation (2)

Re: Create on insert a unique random number

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Create on insert a unique random number
Date: 2008-03-18 17:57:40
Message-ID: 20080318175740.GA7657@a-kretschmer.de (view raw or flat)
Thread:
Lists: pgsql-sql
am  Tue, dem 18.03.2008, um 12:03:31 -0500 mailte Campbell, Lance folgendes:
> I created the following table:
> 
> create table xyz (
> n serial, 
> abc character varying, 
> constraint n_pkey primary key (n));
> 
> Each time I do an insert:
> 
> insert into xyz(abc) values('adf6');
> 
> The field n is not random but is sequential.  Is there something I
> should do to make the serial number random?

Why do you mean to need a random value? But you can use something like
md5(nextval('your_sequence')) as default. But i can't see an advantage.


>  
> 
> -----Original Message-----

Please, no top-posting. I'm reading from top to bottom.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

In response to

pgsql-sql by date

Next:From: Campbell, LanceDate: 2008-03-18 18:40:42
Subject: Re: Create on insert a unique random number
Previous:From: Vivek KheraDate: 2008-03-18 17:56:37
Subject: Re: Create on insert a unique random number

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group