snowflake-cloud-data-platform

Generate dates within a range in Snowflake


I have a table in postgres one of the columns is year which is calculated as :

date_part('year',current_date) + generate_series(-2,4)

so if I take today's date , the output will be :

year
2021
2025
2019
2024
2023
2022
2020

How to achieve the above in snowflake environment.

Thanks in advance


Solution

  • Below snowflake community article will give more in depth info about using functions like SEQ1(),SEQ2(),SEQ4(),SEQ8() and generator functions.

    Generate gap free seq and dates