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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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
bye
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?
>
> http://www.postgresql.org/search.mpl

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Jason Earl 2001-06-07 22:10:41 Re: Create unique field..
Previous Message Nabil Sayegh 2001-06-07 20:14:46 Re: Create unique field..