X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E5A3A9FA2C7 for ; Fri, 22 Sep 2006 16:25:48 -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 54806-08 for ; Fri, 22 Sep 2006 16:25:43 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31815.mail.mud.yahoo.com (web31815.mail.mud.yahoo.com [68.142.206.168]) by postgresql.org (Postfix) with SMTP id 93ADB9FA372 for ; Fri, 22 Sep 2006 16:25:42 -0300 (ADT) Received: (qmail 46466 invoked by uid 60001); 22 Sep 2006 19:25:41 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=RCGM6T3OhtEbePwRaaIKh9Rig5ouE+5A5jxZc5q8WuKwlCGu9g+vn0k8kOI5+avJ6EpFpZ9obQ6cLXc3b0jachXlr6aasBgGDvXEd2QgbPR+rhIR5cCgsk7k9XnqAXtXrPiGNLtO4qEWVLH8vhLS7AXzThXQRqJKQM3r/SzqSSQ= ; Message-ID: <20060922192541.46464.qmail@web31815.mail.mud.yahoo.com> Received: from [63.203.180.122] by web31815.mail.mud.yahoo.com via HTTP; Fri, 22 Sep 2006 12:25:41 PDT Date: Fri, 22 Sep 2006 12:25:41 -0700 (PDT) From: Richard Broersma Jr Subject: Re: How to autoincrement a primary key... To: Doug Hyde , pgsql-sql@postgresql.org In-Reply-To: <000001c6de7b$3a211c70$6501a8c0@laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.228 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS X-Spam-Level: ** X-Archive-Number: 200609/158 X-Sequence-Number: 26369 > 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.