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

Re: Create unique field..

From: "Giorgio A(dot)" <jh(at)libero(dot)it>
To: "Williams, Travis L, NPONS" <tlw(at)att(dot)com>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Create unique field..
Date: 2001-06-07 21:49:55
Message-ID: 002b01c0ef9c$955535a0$0201a8c0@casa (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
try this:

CREATE SEQUENCE "a_name_for_the_seq" start 1 increment 1 maxvalue 2147483647
minvalue 1  cache 1 ;

and when creating a table, add as the first column the following:

"id" int4 DEFAULT nextval('a_name_for_the_seq'::text) NOT NULL

the value of this column will be unique and autoincremental. Plz note that
you won't specify the value of this column when you'll do your INSERT.

hope this helps
Giorgio A.

----- Original Message -----
From: "Williams, Travis L, NPONS" <tlw(at)att(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Sent: Thursday, June 07, 2001 9:58 PM
Subject: [NOVICE] Create unique field..

> All,
> I'm not sure if I'm on the right track here.. I want to create a
> column that is automatically filled in with a unique number when a row is
> created.. I thought that creating a sequence would do this.. and then
> creating a column with a default of nextval('seqname') but it isn't doing
> anything.. any help is appreciated...
> Thanks,
> Travis L. Williams
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?

In response to

pgsql-novice by date

Next:From: Jason EarlDate: 2001-06-07 22:10:41
Subject: Re: Create unique field..
Previous:From: Nabil SayeghDate: 2001-06-07 20:14:46
Subject: Re: Create unique field..

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