Created
November 1, 2016 20:43
-
-
Save sbealer/436de9a7d3605e4972148bc4e7cbd4c6 to your computer and use it in GitHub Desktop.
Redshift Time Dimension SQL
This file contains 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
CREATE VIEW dw.dim_time_vw AS | |
with nums AS ( | |
SELECT TOP 86400 | |
row_number() over ( | |
PARTITION BY NULL ORDER BY id) AS num | |
FROM l_browser) | |
SELECT | |
to_char( | |
DATEADD(second, num-1, cast('2000-01-01' AS date)), 'HH24MISS') AS time_key, | |
to_char( | |
DATEADD(second, num-1, cast('2000-01-01' AS date)), 'HH24:MI:SS') AS time, | |
cast(to_char( | |
DATEADD(second, num-1, cast('2000-01-01' AS date)), 'HH24') AS int) AS hour, | |
cast(to_char( | |
DATEADD(second, num-1, cast('2000-01-01' AS date)), 'MI') AS int) AS minute, | |
cast(to_char( | |
DATEADD(second, num-1, cast('2000-01-01' AS date)), 'SS') AS int) AS second | |
FROM nums; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment