Re: How to autoincrement a primary key... - Mailing list pgsql-sql

From Richard Broersma Jr
Subject Re: How to autoincrement a primary key...
Date
Msg-id 20060922192541.46464.qmail@web31815.mail.mud.yahoo.com
Whole thread Raw
In response to How to autoincrement a primary key...  ("Doug Hyde" <doug.hyde@e-cocreate.com>)
Responses Re: How to autoincrement a primary key...
Re: How to autoincrement a primary key...
List pgsql-sql
> I am sure this is simple, but I don't get it. I am new to PGSQL, coming from
> MySQL - in mysql, you can autoincrement the primary key; in postgre, I am
> not sure how to do this. I have read the documentation, and tried "nextval"
> as the default - I have searched for the datatype SERIAL, but I am using
> navicat and this datatype is not supported. Can someone tell me how to do
> this - I just want the integer value for a primary key to autoincrement by
> one. 

CREATE TABLE bar (id    SERIAL PRIMARY KEY);


Is just shorthand notation for:


CREATE SEQUENCE foo START 1;
CREATE TABLE bar (id integer PRIMARY KEY DEFAULT nextval('bar'));


Also see:
http://www.postgresql.org/docs/8.1/interactive/sql-createtable.html
http://www.postgresql.org/docs/8.1/interactive/sql-createsequence.html

Regards,

Richard Broersma Jr.


pgsql-sql by date:

Previous
From: "Doug Hyde"
Date:
Subject: How to autoincrement a primary key...
Next
From: "Andrew Chilton"
Date:
Subject: Re: How to autoincrement a primary key...