What is the fastest way to generate numbers between two values.
For example:
1st Value: 6,000,000
2nd Value: 7,500,000
I have to create 1,500,000 rows like below
6,000,001
6,000,002
.
.
7,500,000
What is the fastest way to generate numbers between two values.
For example:
1st Value: 6,000,000
2nd Value: 7,500,000
I have to create 1,500,000 rows like below
6,000,001
6,000,002
.
.
7,500,000
This works for me:
create or alter procedure GET_INTEGER_RANGE (
INICIO integer,
FIN integer)
returns (
ACTUAL integer)
AS
begin
actual = inicio;
while (actual<=fin) do
begin
suspend;
actual = actual +1;
end
end
SELECT * FROM GET_INTEGER_RANGE(6000000,7500000);
Not sure if this is the fastest, but it's the only way I can think of:
with recursive numbers (nr) as (
select 6000000
from rdb$database
union all
select nr + 1
from numbers
where nr < 7500000
)
select *
from numbers;
Update: as franbenz pointed out in the comment, Firebird is limited to a recursion depth of 1024 which apparently cannot be changed. So while the basic syntax is correct the above will not work when trying to generate more then 1024 rows.