Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading