From: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> |
---|---|
To: | Doug Hyde <doug(dot)hyde(at)e-cocreate(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: How to autoincrement a primary key... |
Date: | 2006-09-22 19:25:41 |
Message-ID: | 20060922192541.46464.qmail@web31815.mail.mud.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Chilton | 2006-09-22 22:00:29 | Re: How to autoincrement a primary key... |
Previous Message | Doug Hyde | 2006-09-22 19:13:46 | How to autoincrement a primary key... |