Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 0D17A2E030E for ; Mon, 10 Mar 2008 19:04:37 -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 59724-01 for ; Mon, 10 Mar 2008 19:04:11 -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 74B892E028E for ; Mon, 10 Mar 2008 19:04:11 -0300 (ADT) Received: (qmail 28174 invoked by uid 1003); 10 Mar 2008 22:04:07 -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 22:04:07 -0000 X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Mon, 10 Mar 2008 15:03:57 -0700 To: "A. R. Van Hook" ,Jamie Tufnell From: Steve Midgley Subject: Re: works but ... Cc: pgsql-sql@postgresql.org In-Reply-To: <47D5ACD0.9020603@lota.us> References: <47D5ACD0.9020603@lota.us> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Message-Id: <20080310220416.74B892E028E@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/52 X-Sequence-Number: 30380 At 02:49 PM 3/10/2008, A. R. Van Hook wrote: >The following code seems to work but it leads to the following >question(s): >Is there a sequence for each scid,item or is there one sequence that >must be reset >when changing scid? > > $cmd = "select setval('schItem_item_seq', (select max(item)+1 from > schItem where scid=$newScid))"; > $result = $conn->exec($cmd); > $OK += cmp_eq($conn,PGRES_TUPLES_OK, $result->resultStatus); > > $cmd = "insert into schItem (scid, value, iflag, outalts, sidate, > istid) > select $newScid, i.value, i.iflag, i.outalts, i.sidate, > i.istid > from schItem i, schItem s > where (i.scid=$wrongScid and i.item >= $searchItem) > and (s.scid=$newScid) > group by i.value, i.iflag, i.outalts, i.sidate, i.istid, > i.scid"; > $result = $conn->exec($cmd); > $OK += cmp_eq($conn,PGRES_COMMAND_OK, $result->resultStatus); > > $cmd = "delete from schItem where scid = $wrongScid and item >= > $searchItem"; > >ps > the full perl script is attached > >thanks again >art > > >-- >Arthur R. Van Hook Hi Arthur, I'm not totally clear on your question but generally speaking there is one sequence per primary key, by default on each table. So if you reset that key, then your table will start issuing keys at that new number. Another way to be more safe is to "+5" your sequence, so that even if a few inserts slip in, you're still ahead of the game.. Steve