Re: Increment primary key - Mailing list pgsql-general

From wsheldah@lexmark.com
Subject Re: Increment primary key
Date
Msg-id 200204032044.PAA26920@interlock2.lexmark.com
Whole thread Raw
In response to Increment primary key  (impala <bhnnc@yahoo.co.uk>)
List 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.co.uk@interlock.lexmark.com> on 04/03/2002 01:58:32 PM

To:   pgsql-general%postgresql.org@interlock.lexmark.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@postgresql.org





pgsql-general by date:

Previous
From: impala
Date:
Subject: Increment primary key
Next
From:
Date:
Subject: Re: do foreign key checks lock parent table ?