Created
November 21, 2012 13:54
-
-
Save waveform80/4124953 to your computer and use it in GitHub Desktop.
Example of recursive date generation in 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 some_dates AS | |
WITH RECURSIVE dates(i, d) AS ( | |
VALUES (1, DATE('1970-01-01')) | |
UNION ALL | |
SELECT i + 1, d + 1 DAY FROM dates WHERE d < DATE('2070-12-31') | |
) | |
SELECT | |
d.d AS a_date, | |
YEAR(d.d) AS a_year, | |
MONTH(d.d) AS a_month, | |
DAY(d.d) AS a_day | |
FROM dates; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment