Looking to either Explode or unnest into an array in Snowflake SQL

615 views Asked by At

In the past I've used either the explode function(sql) or unnest in (bigquery) to expand one row into several. For instance I've transformed the current data row: enter image description here into the following: enter image description here

Does anyone know if snowflake sql has a function which allows me to do this? I can't seem to find one

1

There are 1 answers

2
Gordon Linoff On

You can use generator():

select t.id, t.subscription, t.signup_date,
       dateadd(month, row_number() over (order by null) - 1, t.signup_date) as tenure
from t cross join
     table (generator(row_count => 12));

I'm a little baffled on why you think you would do this with explode() or unnest() in another database. The key idea is generating the series, I think, not turning it into rows.