Home > Net >  How to match elements of a BigQuery array with dates by starting from a given date?
How to match elements of a BigQuery array with dates by starting from a given date?

Time:09-03

How can I match elements of an array with dates by starting from a given date until end of the array for every day?

e.g:

The table I have:

numbers start_date
[1, 2, 3] 2022-01-01

SQL to create this table:

SELECT [1, 2, 3] as numbers, CAST('2022-01-01' AS DATE) AS start_date;

The table I expect to have from the table above:

number matched_date
1 2022-01-01
2 2022-01-02
3 2022-01-03

Thank you for your answers.

CodePudding user response:

Consider below approach

select number, date(start_date)   offset as matched_date
from your_table, unnest(numbers) number with offset          

if applied to sample data in your question - output is

enter image description here

  • Related