Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

hsqldb

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?

like image 339
caeycae Avatar asked Nov 26 '25 13:11

caeycae


1 Answers

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)

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!