Nextval not working as expected

117 views
Skip to first unread message

Nitai

unread,
Jul 16, 2008, 9:58:26 AM7/16/08
to H2 Database
Hi there

First of, thank you for the H2 database. I am mainly using the Oracle
database and found H2 which I am embedding right now into our
application.

I came upon a strange "error" with NEXTVAL. I have setup the sequence
with "create sequence myseq". Then I am selecting the dual table with;

SELECT CATEGORIES_SEQ.nextval AS id FROM dual

This returns me the next value (correct). I then insert that value to
different tables. Problem is that the NEXT time I use the same select
again, it "jumps" one number, meaning I get "1", "3", "5", etc.

Is this a setting or am I doing this wrong?

Kind Regards,
Nitai

Nitai

unread,
Jul 16, 2008, 9:59:55 AM7/16/08
to H2 Database
Yes, I am using the latest version 1.0.75

Thomas Mueller

unread,
Jul 16, 2008, 10:22:37 AM7/16/08
to h2-da...@googlegroups.com
Hi,

Sorry I can't reproduce this problem. Here is what I did:

drop sequence CATEGORIES_SEQ;
create sequence CATEGORIES_SEQ;
SELECT CATEGORIES_SEQ.nextval AS id FROM dual;
--> 1
SELECT CATEGORIES_SEQ.nextval AS id FROM dual;
--> 2
SELECT CATEGORIES_SEQ.nextval AS id FROM dual;
--> 3

Maybe you are using the sequence as a default value in one of the
tables, or call the sequence twice in some other way?

Regards,
Thomas

Nitai

unread,
Jul 16, 2008, 11:40:48 AM7/16/08
to H2 Database
Strange I could have sworn..... I did a test page and it did not work
but in the app it works........ Never mind then. Thank you for the
fast reply.

On Jul 16, 4:22 pm, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages