X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 82C69D1B345 for ; Fri, 2 Jul 2004 17:29:44 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57305-01 for ; Fri, 2 Jul 2004 20:29:43 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 6731CD1B211 for ; Fri, 2 Jul 2004 17:29:40 -0300 (ADT) Received: (qmail 3912 invoked by uid 500); 2 Jul 2004 20:36:23 -0000 Date: Fri, 2 Jul 2004 15:36:23 -0500 From: Bruno Wolff III To: teknet@poczta.onet.pl Cc: pgsql-admin@postgresql.org Subject: Re: SERIAL type not autoincremented Message-ID: <20040702203623.GA3839@wolff.to> Mail-Followup-To: teknet@poczta.onet.pl, pgsql-admin@postgresql.org References: <200407021131.57987.mike@nachbaur.com> <20040702194010Z137290-15166+26852@kps2.test.onet.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20040702194010Z137290-15166+26852@kps2.test.onet.pl> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/51 X-Sequence-Number: 14119 On Fri, Jul 02, 2004 at 21:40:02 +0200, teknet@poczta.onet.pl wrote: > i found the problem: > >   > > sys=> create table test2( > sys(> id serial, > sys(> name varchar(10), > sys(> primary key(id) > sys(> ); > NOTICE:  CREATE TABLE will create implicit sequence "test2_id_seq" for > "serial" column "test2.id" > NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "test2_pkey" > for table "test2" > CREATE TABLE > sys=> insert into test2 values(1,'myname'); > INSERT 18765 1 > sys=> insert into test2 (name) values('myname2'); > ERROR:  duplicate key violates unique constraint "test2_pkey" > sys=> > > Why is it so ? Because you are inserting records without using the sequence. The serial type is really a short cut for specifying that the default value is the value of a sequence created for that column. If you insert records without using the default, then you also need to set the value of the sequence higher than the largest value so far. You can use the setval function to do this.