Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id DF34A9FB204 for ; Wed, 7 Mar 2007 12:02:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 10352-05 for ; Wed, 7 Mar 2007 12:02:10 -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 7E9FA9FB31D for ; Wed, 7 Mar 2007 12:02:09 -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 1HOyWu-0007Nw-Pk for pgsql-jdbc@postgresql.org; Wed, 07 Mar 2007 16:58:17 +0100 Received: from giuseppe by scarafaggio with local (Exim 4.63) (envelope-from ) id 1HOyeS-00037S-7A for pgsql-jdbc@postgresql.org; Wed, 07 Mar 2007 17:06:04 +0100 Subject: Re: Transaction atomicity From: Giuseppe Sacco To: pgsql-jdbc@postgresql.org In-Reply-To: <45EEDF37.90201@enterprisedb.com> References: <1173268752.20645.29.camel@scarafaggio> <1173280119.20645.39.camel@scarafaggio> <45EEDF37.90201@enterprisedb.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Wed, 07 Mar 2007 17:06:03 +0100 Message-Id: <1173283563.20645.53.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.334 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: * X-Archive-Number: 200703/75 X-Sequence-Number: 16789 Hi Heikki, Il giorno mer, 07/03/2007 alle 15.50 +0000, Heikki Linnakangas ha scritto: > Giuseppe Sacco wrote: > > Thanks for this suggestion. I have been evaluating the use of sequences > > in my application, but I was looking for a more portable code (this code > > have to run on postgresq 8.1, mysql 5, oracle 9.2 and sql-server 2005). > > As you may know postgresql nextval syntax isn't as required by the > > standard; and other vendors use different syntax too. Moreover it would > > make my code really complex since I would need a new sequence for any > > connected user. > > A more portable way to use sequences is to define a default expression > on the column when you create the table, like this: > > CREATE TABLE foo ( > key int DEFAULT (nextval('foo_seq')) PRIMARY KEY > data ... > ) [...] 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 sequences I would probably need to create all these sequences, then use the right sequence to get the nextval and then call my INSERT statement with the right value. This imply the explicitly use of a sequence for every insert. This is not a big problem, I just need to have a special case for every dbms. Thanks again, Giuseppe