Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 529759FA456 for ; Wed, 7 Mar 2007 11:50:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 31838-03 for ; Wed, 7 Mar 2007 11:50:16 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173]) by postgresql.org (Postfix) with ESMTP id 9251A9FA381 for ; Wed, 7 Mar 2007 11:50:21 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so559497ugf for ; Wed, 07 Mar 2007 07:50:17 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=OxuJMrIWK7F8srxTWBzlKBkMaOVHIbdRA3R0Rt5B3sETIKA5npAoVEyZyiL/VEF7p/1mdsIhCTBtXieSlZR/+PL+YV5oJFJ+rNp9aLXCj9AlQJz3j45KYbKeloq7OnvjiyCjh6Sqw01XY/XVva9btUxbsZR1nk/wuJ4D0xrX/IA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=of29vl/snC+gfXNhnH6XzEHbtrMum9Fjwd50/kJLitKZxCOR1t9uuuhGRIWMsbJiW4lq+aNFCVo+TJcWk9SNdrFNcDU7rZ+9572hqNtO1uBaqAKfMNexqDBuohievuXo0i8cbImVNB3Hzi8VYwSzUnU41MAvH8BPhWnn5Tq1cSQ= Received: by 10.67.19.13 with SMTP id w13mr4608912ugi.1173282617050; Wed, 07 Mar 2007 07:50:17 -0800 (PST) Received: from ?172.24.32.107? ( [62.232.55.118]) by mx.google.com with ESMTP id 27sm2211545ugp.2007.03.07.07.50.14; Wed, 07 Mar 2007 07:50:15 -0800 (PST) Message-ID: <45EEDF37.90201@enterprisedb.com> Date: Wed, 07 Mar 2007 15:50:15 +0000 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.8 (X11/20061116) MIME-Version: 1.0 To: Giuseppe Sacco CC: pgsql-jdbc@postgresql.org Subject: Re: Transaction atomicity References: <1173268752.20645.29.camel@scarafaggio> <1173280119.20645.39.camel@scarafaggio> In-Reply-To: <1173280119.20645.39.camel@scarafaggio> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/73 X-Sequence-Number: 16787 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 ... ) Now if you don't give key a value in your insert statement, it'll be assigned the next value from the sequence automatically. For example: INSERT INTO foo (data, ...) VALUES ('bar', ...); The create table syntax isn't portable, AFAIK, but there's a similar construct available on all common DBMSs. You could use the same SQL in your application to insert rows, only the DDL to create tables would be different on different DBMSs. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com