Re: Increment primary key

From: wsheldah(at)lexmark(dot)com
To: impala <bhnnc(at)yahoo(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Increment primary key
Date: 2002-04-03 20:44:19
Message-ID: 200204032044.PAA26920@interlock2.lexmark.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The easiest way is to do it in the CREATE TABLE statement:
CREATE TABLE mytable (id SERIAL PRIMARY KEY, name text);

That will make id an integer, automatically create a separate SEQUENCE, and bind
id to that sequence so that it is incremented properly.
The online docs elaborate on this; look for CREATE SEQUENCE, CREATE TABLE, and
SERIAL. Best of luck!

Wes

impala <bhnnc%yahoo(dot)co(dot)uk(at)interlock(dot)lexmark(dot)com> on 04/03/2002 01:58:32 PM

To: pgsql-general%postgresql(dot)org(at)interlock(dot)lexmark(dot)com
cc: (bcc: Wesley Sheldahl/Lex/Lexmark)
Subject: [GENERAL] Increment primary key

Hi

I created a table and the primary key must increment
automatically with e.g 1 each time I insert a new row.
How do I write the psql code to make this happen?

Nic

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

Browse pgsql-general by date

  From Date Subject
Next Message Oberpriller, Wade D. 2002-04-03 21:11:43 hex values
Previous Message Steve Lane 2002-04-03 20:03:21 Re: Postgres/PHP, Apache child processes dying