Skip to content

Instantly share code, notes, and snippets.

@waveform80
Created November 21, 2012 13:54
Show Gist options
  • Save waveform80/4124953 to your computer and use it in GitHub Desktop.
Save waveform80/4124953 to your computer and use it in GitHub Desktop.
Example of recursive date generation in SQL
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