Generate Series of Dates in Snowflake

As Snowflake doesn't have a native generate_series function, here is our solution to generating a table of incrementing dates, starting from the current date, in Snowflake. It is currently set to generate 1095 rows (3 years) of dates.

select
  dateadd(day, '-' || seq4(), current_date()) as dte
from
  table
    (generator(rowcount => 1095))
2replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Thank you! This worked great. I'm also trying to generate the same table but starting with a date in the future. I've tried:

    select
      dateadd(day, '-' || seq4(), 2030-01-01 as dte
    from
      table
        (generator(rowcount => 7300))

     

    But that didn't work. Also tried it without "as dte" but that didn't work either. I'm a total beginner in SQL since I work with databases only through a GUI. I'd really appreciate any explanation of why the replacement I tried did not work, and what to try instead. 

    Reply Like
      • Neha Kumar
      • Solutions Engineer
      • Neha_Kumar
      • 7 days ago
      • 1
      • Reported - view

      Mia Oppelstrup What type of SQL are you using? If you're using snowflake all you're missing is a closing parenthesis after the date, and single quotes around 2030-01-01. (Without the single quotes, SQL interprets the dashes as minus signs). Hope this helps!

      select
        dateadd(day, '-' || seq4(), '2030-01-01') as dte
      from
        table
          (generator(rowcount => 7300))
      Reply Like 1
Like5 Follow
  • 5 Likes
  • 7 days agoLast active
  • 2Replies
  • 78Views
  • 3 Following