Skip to content

Instantly share code, notes, and snippets.

@cdussud
Created January 18, 2021 19:20
Show Gist options
  • Save cdussud/d945b2ef66d2bbee2e524436cd679af6 to your computer and use it in GitHub Desktop.
Save cdussud/d945b2ef66d2bbee2e524436cd679af6 to your computer and use it in GitHub Desktop.
Sequence of numbers in Redshift
-- generate 10M numbers on Redshift
with digit as (
select 0 as d union all
select 1 union all select 2 union all select 3 union all
select 4 union all select 5 union all select 6 union all
select 7 union all select 8 union all select 9
),
seq as (
select a.d + (10 * b.d) + (100 * c.d) + (1000 * d.d) + (10000 * e.d) + (100000 * f.d) + (1000000 * g.d) as num
from digit a
cross join
digit b
cross join
digit c
cross join
digit d
cross join
digit e
cross join
digit f
cross join
digit g
order by 1
)
select seq.num
from seq;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment