Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 58AC99FB1F7 for ; Sat, 23 Sep 2006 03:28:08 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 29694-01 for ; Sat, 23 Sep 2006 03:28:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp20.kymp.net (smtp20.kymp.net [80.248.96.137]) by postgresql.org (Postfix) with ESMTP id A08419FB1E8 for ; Sat, 23 Sep 2006 03:28:02 -0300 (ADT) Received: from [192.168.0.100] (static-241-66.kymp.net [213.130.241.66]) by smtp20.kymp.net (8.13.3/8.13.3) with SMTP id k8N6Rvqs023803; Sat, 23 Sep 2006 09:27:57 +0300 From: Aarni =?iso-8859-1?q?Ruuhim=E4ki?= Reply-To: aarni@kymi.com Organization: KYMI.com To: pgsql-sql@postgresql.org Subject: Re: How to autoincrement a primary key... Date: Sat, 23 Sep 2006 09:27:57 +0300 User-Agent: KMail/1.6.2 References: <000001c6de7b$3a211c70$6501a8c0@laptop> <20060922192541.46464.qmail@web31815.mail.mud.yahoo.com> In-Reply-To: Cc: "Doug Hyde" MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <200609230927.58000.aarni@kymi.com> X-Virus-Scanned: by amavisd-new X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200609/161 X-Sequence-Number: 26372 On Saturday 23 September 2006 01:12, Thomas Kellerer wrote: > Richard Broersma Jr wrote on 22.09.2006 21:25: > >> 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('foo')); > > Well the shorthand notation has a minor gotcha: you cannot drop the > sequence that has been created automatically. Only if you drop the column > itself. Should not be a problem, but it is a difference between a SERIAL > PRIMARY KEY definition and the "verbose" mode > > Thomas > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match Verbosily you can have even more control over the sequence. With SERIAL the default is something like CREATE SEQUENCE foo INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; By hand you can define e.g. CREATE SEQUENCE foo START n INCREMENT BY n MAXVALUE n MINVALUE n CACHE 1; BR, Aarni =2D-=20 Aarni Ruuhim=E4ki **Kmail** **Fedora Core Linux**