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 90C8CD1B34A for ; Fri, 2 Jul 2004 18:07:36 -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 72066-09 for ; Fri, 2 Jul 2004 21:07:36 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 64D05D1B470 for ; Fri, 2 Jul 2004 18:07:33 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i62L7XZ3042114 for ; Fri, 2 Jul 2004 21:07:33 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i62Km9V2038324 for pgsql-admin@postgresql.org; Fri, 2 Jul 2004 20:48:09 GMT From: Mike Rylander X-Newsgroups: comp.databases.postgresql.admin Subject: Re: SERIAL type not autoincremented Date: Fri, 02 Jul 2004 16:32:02 -0400 Organization: Hub.Org Networking Services Lines: 51 Message-ID: References: <20040702194010Z137290-15166+26852@kps2.test.onet.pl> Reply-To: miker@purplefrog.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Complaints-To: usenet@news.hub.org User-Agent: KNode/0.7.6 To: pgsql-admin@postgresql.org 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/98 X-Sequence-Number: 14166 Larry Rosenman wrote: > 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 ? >> >> >> >> Thanx >> >> Michal > > Because you didn't let the serial column do it's magic. > > Try: > > Insert into test2(name) values('myname'); > Insert into test2(name) values('myname2'); > > That should work. > > Always let a serial column pick the number. Or, if you must specify the column, specify DEFAULT for the value: INSERT INTO test2 (id,name) values (DEFAULT,'myname3'); > > LER > >