Question

How generate a list of rows of numers in a range in HSQLDB?

I need to insert a whole range of numbers in the base.

something like this

INSERT INTO numers
VALUES
(50001)
(50002)
...
(59999)

In oracle, is can be done with "CONNECT BY LEVEL", but how can i do it in HSQLDB?

Was it helpful?

Solution

HyperSQL (as HSQLDB is now called) has a function similar to Postgres' generate_series(). Using sequence_array together with the unnest() function you can generate a list of values:

insert into numbers (some_number)
select nr
from unnest(sequence_array(1, 100, 1)) as i(nr)

If you want to start with a different number, just supply that as an argument to the sequence_array function.

insert into numbers (some_number)
select nr
from unnest(sequence_array(50000, 59999, 1)) as i(nr)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top