Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 8DCC19FB5B5 for ; Wed, 7 Mar 2007 12:35:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 27904-09 for ; Wed, 7 Mar 2007 12:35:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from eppesuigoccas.homedns.org (host245-172-dynamic.0-87-r.retail.telecomitalia.it [87.0.172.245]) by postgresql.org (Postfix) with ESMTP id 2795E9FB28E for ; Wed, 7 Mar 2007 12:35:16 -0400 (AST) Received: from 89-96-243-184.ip14.fastwebnet.it ([89.96.243.184] helo=scarafaggio) by eppesuigoccas.homedns.org with esmtpsa (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1HOz2n-0000FH-DG for pgsql-jdbc@postgresql.org; Wed, 07 Mar 2007 17:31:13 +0100 Received: from giuseppe by scarafaggio with local (Exim 4.63) (envelope-from ) id 1HOzAK-0003Is-Ja for pgsql-jdbc@postgresql.org; Wed, 07 Mar 2007 17:39:00 +0100 Subject: Re: Transaction atomicity From: Giuseppe Sacco To: pgsql-jdbc@postgresql.org In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Wed, 07 Mar 2007 17:39:00 +0100 Message-Id: <1173285540.20645.59.camel@scarafaggio> Mime-Version: 1.0 X-Mailer: Evolution 2.6.3 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.134 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: * X-Archive-Number: 200703/78 X-Sequence-Number: 16792 Il giorno mer, 07/03/2007 alle 08.12 -0800, Jeff Hubbach ha scritto: > On 3/7/07 9:06 AM, "Giuseppe Sacco" > > wrote: > > > You are right, but I need different sequences for every user, i.e., > if > > two users insert on the same table then I need a way to use > different > > sequence. The reason of this is that I have to split my application > into > > a few different postgresql instances based in different offices. > Every > > night all instances synchronise their data (this is and INSERT only > > table), so I need a different table sequence in every office (or > group > > of users or single user). > > Using select(max(id)) won't work in this case, either (if I'm > understanding > your setup correctly). > It works since I assigned ranges to each office. The query I wrote in my original post was: final String query = "INTO table (docId,seqNr) " + "VALUES (?, (SELECT 1 + coalesce (max(seqNr), 0) "+ "FROM table " + "WHERE seqNr BETWEEN 0 AND (9223372036854775807-1) ))"; as you may see, I look for a MAX in a specific range. Every office has a different range. > > Why not have a compound key on this table, with an ID generated by a > sequence (one sequence, named the same, for each instance of > PostgreSQL for > each office), and an Office ID that is static for each instance? Then > the > merge/sync would go through without a hitch. You are right, this is a second option, but we cannot adopt it since we have a lot of table that use foreign keys against this one. Adding one field would require a change in every table in order to complete the foreign key constraint. Thanks for you hint, Giuseppe