I have a table with one column duration
containing integer values, and I'm trying to build an other column, using a sql query, that would contain an a list of integer between 1 and the value in the duration
column.
For example:
duration | range
3 | [1, 2, 3]
3 | [1, 2, 3]
2 | [1, 2]
1 | [1]
...
I found a potential solution in JS.
create or replace function list_range(DURATION double)
returns VARCHAR
language javascript
strict
as 'return [...Array(DURATION).keys()];';
SELECT
t.*,
list_range(t.duration) as range
FROM table t
What do you think of this solution? Can it be optimized?