Skip to content

Instantly share code, notes, and snippets.

@tecmaverick
Last active March 23, 2022 01:11
Show Gist options
  • Save tecmaverick/8a012d9c88bffe4eb917f82d404a7426 to your computer and use it in GitHub Desktop.
Save tecmaverick/8a012d9c88bffe4eb917f82d404a7426 to your computer and use it in GitHub Desktop.
Redshift Integer Sequence Generator v1
with ten as (
select 0 as number union
select 1 union
select 2 union
select 3 union
select 4 union
select 5 union
select 6 union
select 7 union
select 8 union
select 9
),
hundred as (
-- returns value from 0 to 99
select tens2.number * 10 + tens1.number as number from ten tens1, ten tens2
),
thousand as (
-- returns value from 0 to 999
select ten.number * 100 + hundred.number as number from hundred, ten
),
ten_thousand as (
-- returns value from 0 to 9,999
select ten.number * 1000 + thousand.number as number from thousand, ten
),
hundred_thousand as (
-- returns value from 0 to 99,999
select ten.number * 10000 + ten_thousand.number as number from ten_thousand, ten
),
million as (
-- returns value from 0 to 999,999
select ten.number * 100000 + hundred_thousand.number as number from hundred_thousand, ten
),
ten_million as (
-- returns value from 0 to 99,99999
select ten.number * 1000000 + million.number as number from million, ten
)
select * from ten_million order by number
select count(number) from ten_million
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment