hazalciplak
hazalciplak

Reputation: 506

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

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.

Upvotes: 0

Views: 202

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172993

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

Upvotes: 2

Related Questions