From: Heikki Linnakangas <heikki@enterprisedb.com>
To: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Transaction atomicity
Date: Wed, 07 Mar 2007 15:50:15 +0000
Message-ID: <45EEDF37.90201@enterprisedb.com> (raw)
In-Reply-To: <1173280119.20645.39.camel@scarafaggio>
References: <1173268752.20645.29.camel@scarafaggio>
<C71D4FFF-944B-4786-8A56-FC0236782B40@fastcrypt.com>
<1173280119.20645.39.camel@scarafaggio>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: heikki@enterprisedb.com, giuseppe@eppesuigoccas.homedns.org
Subject: Re: Transaction atomicity
In-Reply-To: <45EEDF37.90201@enterprisedb.com>
References: <1173268752.20645.29.camel@scarafaggio> <C71D4FFF-944B-4786-8A56-FC0236782B40@fastcrypt.com> <1173280119.20645.39.camel@scarafaggio> <45EEDF37.90201@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox