Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 714842E028C for ; Mon, 10 Mar 2008 15:10:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 71371-01-9 for ; Mon, 10 Mar 2008 15:09:55 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from starfish.geekisp.com (mail.geekisp.com [216.168.135.169]) by postgresql.org (Postfix) with ESMTP id EEA662E2DF5 for ; Mon, 10 Mar 2008 15:09:19 -0300 (ADT) Received: (qmail 12219 invoked by uid 1003); 10 Mar 2008 18:09:15 -0000 Received: from adsl-76-253-94-54.dsl.pltn13.sbcglobal.net (HELO dino-1.misuse.org) (public@misuse.org@76.253.94.54) by mail.geekisp.com with (DHE-RSA-AES256-SHA encrypted) SMTP; 10 Mar 2008 18:09:15 -0000 X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Mon, 10 Mar 2008 11:09:04 -0700 To: pgsql-sql@postgresql.org From: Steve Midgley Subject: Re: Insert problem In-Reply-To: <20080310162235.BB1422E024B@postgresql.org> References: <20080310162235.BB1422E024B@postgresql.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Message-Id: <20080310180919.EEA662E2DF5@postgresql.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200803/51 X-Sequence-Number: 30379 At 09:20 AM 3/10/2008, pgsql-sql-owner@postgresql.org wrote: >Date: Mon, 10 Mar 2008 00:14:12 +0000 >From: "Jamie Tufnell" >To: pgsql-sql@postgresql.org >Subject: Re: Insert problem >Message-ID: > >[snip] > > table defination > > > > create sequence schItem_item_seq > > create table schItem > > (scid int NOT NULL references schedule ON DELETE CASCADE, > > item int NOT NULL default nextval('schItem_item_seq'), > >[snip] > >It looks like there's already a row where scid=2072 and >item=nextval('schItem_item_seq'). > >Try: > >SELECT setval('schItem_item_seq', (SELECT max(item)+1 FROM schItem)); > >And then run your query again. > >Cheers, >J. A friendly amendment to Jamie's (correct) advice. Be sure that no other tools are obtaining id's from the sequence or inserting rows into schItem when you run this.. (Safest way is to have the db offline when running this). I got some good info from the experts here about this while back and wrote up a little blog article detailing the issue (in short it's a big pain to do it while the db is online, with no obvious sure-fire solution): http://www.misuse.org/science/2007/08/07/obtaining-a-block-of-ids-from-a-sequence-in-postgresql/ I hope this helps a little! Steve