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 BF2129FB313 for ; Fri, 22 Sep 2006 19:12:19 -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 18795-05 for ; Fri, 22 Sep 2006 19:12:15 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 0D8FC9FB2AE for ; Fri, 22 Sep 2006 19:12:14 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1GQtFl-0008M0-6u for pgsql-sql@postgresql.org; Sat, 23 Sep 2006 00:12:13 +0200 Received: from ppp-82-135-71-17.dynamic.mnet-online.de ([82.135.71.17]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 23 Sep 2006 00:12:13 +0200 Received: from spam_eater by ppp-82-135-71-17.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 23 Sep 2006 00:12:13 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Thomas Kellerer Subject: Re: How to autoincrement a primary key... Date: Sat, 23 Sep 2006 00:12:00 +0200 Lines: 24 Message-ID: References: <000001c6de7b$3a211c70$6501a8c0@laptop> <20060922192541.46464.qmail@web31815.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: ppp-82-135-71-17.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.0 In-Reply-To: <20060922192541.46464.qmail@web31815.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.208 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/160 X-Sequence-Number: 26371 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('bar')); > 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