pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Broersma Jr <rabroersma@yahoo.com>
To: Doug Hyde <doug.hyde@e-cocreate.com>
To: pgsql-sql@postgresql.org
Subject: Re: How to autoincrement a primary key...
Date: Fri, 22 Sep 2006 12:25:41 -0700 (PDT)
Message-ID: <20060922192541.46464.qmail@web31815.mail.mud.yahoo.com> (raw)
In-Reply-To: <000001c6de7b$3a211c70$6501a8c0@laptop>

> 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.



view thread (5+ messages)  latest in thread

Message-ID: <20060922192541.46464.qmail@web31815.mail.mud.yahoo.com>
Permalink:  ../20060922192541.46464.qmail@web31815.mail.mud.yahoo.com/
Also on:    postgresql.org/message-id/20060922192541.46464.qmail@web31815.mail.mud.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rabroersma@yahoo.com, doug.hyde@e-cocreate.com
  Subject: Re: How to autoincrement a primary key...
  In-Reply-To: <20060922192541.46464.qmail@web31815.mail.mud.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox