I am using hsqldb-1.8.0.10
and I want to use the sequence feature. I launch the DatabaseManager
from the jar file as follows:
java -cp lib/hsqldb.jar org.hsqldb.util.DatabaseManager
I run these requests:
CREATE TABLE test (ID bigint)
CREATE SEQUENCE seq START WITH 1 INCREMENT BY 1
SELECT NEXT VALUE FOR seq FROM test
There is no output. If I insert some rows in the table, it works fine and displays 1
.
Is it a normal comportment? Is there a way to get a value with an empty table?
Yes, this is normal. The statement below returns one row for each row of the table. It doesn't matter what you put between SELECT and FROM (except aggregate functions).
SELECT <anything you put here> FROM test
The NEXT VALUE FOR seq
is like a function that return the next value each time it is called.
If you do not have to use version 1.8.0, use the latest version of HSQLDB as it supports a more extensive syntax.