Created
January 29, 2021 19:48
-
-
Save cdussud/02b32c786b3e3e967cf25d582e50511c to your computer and use it in GitHub Desktop.
How to generate a numbers table in Redshift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Generates a list of sequential integers | |
-- How it works: | |
-- empty_rows is 36 rows of 1 | |
-- cross join with itself any number of times as needed | |
-- a -> 36 rows | |
-- a, b -> 36*36 rows | |
-- a, b, c -> 36*36*36 rows | |
-- row_number gives us our integer for the table | |
WITH empty_rows as ( | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL | |
SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 | |
) | |
SELECT row_number() over () as row_num | |
FROM empty_rows as a, empty_rows as b, empty_rows as c, empty_rows as d, empty_rows as e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment