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 15F29528B7 for ; Sat, 18 Jun 2005 11:06:42 -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 67492-07 for ; Sat, 18 Jun 2005 14:06:38 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id 3B0ED52854 for ; Sat, 18 Jun 2005 11:06:37 -0300 (ADT) Received: (qmail 15961 invoked by uid 500); 18 Jun 2005 14:06:10 -0000 Date: Sat, 18 Jun 2005 09:06:10 -0500 From: Bruno Wolff III To: "Hortschitz, Stefan" Cc: pgsql-admin@postgresql.org Subject: Re: failed insert into serial-type row Message-ID: <20050618140610.GA15547@wolff.to> Mail-Followup-To: Bruno Wolff III , "Hortschitz, Stefan" , pgsql-admin@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/149 X-Sequence-Number: 17904 On Mon, Jun 13, 2005 at 21:58:37 +0200, "Hortschitz, Stefan" wrote: > > CREATE TABLE session.preferences > ( > id serial NOT NULL, > name varchar(50), > value varchar(255), > CONSTRAINT session_preferences_pkey PRIMARY KEY (id) > ) > WITHOUT OIDS; > ALTER TABLE session.preferences OWNER TO web; > -------------------------------- > > and sometimes if i'm adding new rows to the table with statements like > this: > insert into (name,value) ('xy','xy'); > the database only returns an 'duplicate key on primary key', which > should be prevented by the serial-datatype, or? how could it be, that > two rows become the same id?? > if i execute the insert-statement again it works. > > the created serial-sequence looks like this: > -------------------------------- > CREATE SEQUENCE session.preferences_id_seq > INCREMENT 1 > MINVALUE 1 > MAXVALUE 9223372036854775807 > START 2487 > CACHE 1; > ALTER TABLE session.preferences_id_seq OWNER TO web; > -------------------------------- > > what can I do against the duplicate-key problem? is it a configuration, > sql or operating-system specific problem? Most likely you recreated the table and reloaded it at some point without restoring the sequence value. What you want to do now is set the sequence to the highest value of id in the table. Something like: SELECT setval('preferences_id_seq',(SELECT max(id) FROM session.preferences);