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

Re: Create on insert a unique random number

From: "Campbell, Lance" <lance(at)uiuc(dot)edu>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>,<pgsql-sql(at)postgresql(dot)org>
Subject: Re: Create on insert a unique random number
Date: 2008-03-18 17:03:31
Message-ID: B10E6810AC2A2F4EA7550D072CDE8760CDDC33@SAB-FENWICK.sab.uiuc.edu (view raw or flat)
Thread:
Lists: pgsql-sql
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?

Thanks,


Lance Campbell
Project Manager/Software Architect
Web Services at Public Affairs
University of Illinois
217.333.0382
http://webservices.uiuc.edu
 

-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org
[mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of A. Kretschmer
Sent: Tuesday, March 18, 2008 11:52 AM
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Create on insert a unique random number

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.


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

Responses

pgsql-sql by date

Next:From: paul riversDate: 2008-03-18 17:33:29
Subject: Re: Create on insert a unique random number
Previous:From: A. KretschmerDate: 2008-03-18 16:51:39
Subject: Re: Create on insert a unique random number

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