Re: Create unique field.. - Mailing list pgsql-novice

From Nabil Sayegh
Subject Re: Create unique field..
Date
Msg-id 991944886.2619.0.camel@billy.labor.localnet
Whole thread Raw
In response to Create unique field..  ("Williams, Travis L, NPONS" <tlw@att.com>)
List pgsql-novice
On 07 Jun 2001 14:58:17 -0500, Williams, Travis L, NPONS wrote:
> 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...
>

CREATE TEMP TABLE tempo (a text, id serial PRIMARY KEY);
INSERT INTO tempo VALUES ('foo');
INSERT INTO tempo VALUES ('bar');
SELECT * from tempo;

foo 1
bar 2

You can leave out the PRIMARY KEY, or insted use UNIQUE, or whatever ...

cu

--
 Nabil Sayegh



pgsql-novice by date:

Previous
From: Ryan Ho
Date:
Subject: Re: Multiple Columns Keys - Good or Bad idea?
Next
From: "Nabil Sayegh"
Date:
Subject: Re: How do I start postmaster with -i for tcp-ip