X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7C276D1B8B5 for ; Mon, 22 Sep 2003 14:16:18 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 35900-03 for ; Mon, 22 Sep 2003 11:15:51 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 9B6ABD1B55A for ; Mon, 22 Sep 2003 11:15:46 -0300 (ADT) Received: (qmail 23670 invoked by uid 500); 22 Sep 2003 14:22:43 -0000 Date: Mon, 22 Sep 2003 09:22:43 -0500 From: Bruno Wolff III To: sad Cc: pgsql-sql@postgresql.org Subject: Re: auto_increment Message-ID: <20030922142243.GA23419@wolff.to> Mail-Followup-To: sad , pgsql-sql@postgresql.org References: <008501c37f35$832e26e0$1f00a8c0@middinkcomp> <1064038995.5359.70.camel@linda.lfix.co.uk> <200309220915.04899.sad@bankir.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200309220915.04899.sad@bankir.ru> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/252 X-Sequence-Number: 15230 On Mon, Sep 22, 2003 at 09:15:04 +0400, sad wrote: > On Saturday 20 September 2003 10:23, you wrote: > > On Sat, 2003-09-20 at 06:10, Muhyiddin A.M Hayat wrote: > > > How to Create auto_increment field in PostreSQL. > > > Can I create them using Trigger. > > > > Use the SERIAL datatype. See also the functions nextval(), currval() > > and setval(). > > I believe it is better to EXPLICITLY declare a SEQUENCE and > set the default value nextval() to the field. The disadvantage of that system is that the dependency isn't detected. With serial type you won't be able to drop the sequence without dropping the column and when you drop the table, the sequence will get dropped as well. (The preceding applies to 7.4. Things may not be checked as well in 7.3.)