Re: Auto Increment

From: prinsarian(at)zonnet(dot)nl (Arian Prins)
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Auto Increment
Date: 2001-10-22 07:30:16
Message-ID: 3bd3ca9f.5654630@news.amc.uva.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 22 Oct 2001 12:06:21 +0530, "Mayuresh Kadu"
<mayureshk(at)aftek(dot)com> wrote:

>hi all,
>
>could anyone tell me how to make a primary key to AUTO INCREMENT. The
>document is not exactly very explainatory about it :)
>
>Thankx in advance ...
>
>
>
>Mayuresh
>
>

Try first creating a sequence and then using the sequence as a default
value in your table:

-- STEP 1: create sequence
create sequence mytableid_seq;

-- STEP 2: create table
create table mytable (
id int default nextval ('mytableid_seq'),
anyvalue varchar
primary key (id));

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message guard 2001-10-22 09:14:32 can't update 'c:\windows'
Previous Message Reiner Dassing 2001-10-22 06:42:40 Index of a table is not used (in any case)