for two different timestamps, let\'s say timestamp(\'2015-02-01\') and timestamp (\'2015-02-12\'), I want a column with all the dates in between. Like this (12 Rows) 2015-
You can do that with a cross join on a public dataset (fh-bigquery:geocode.numbers_65536
) where you have numbers up to: 65536
SELECT date(DATE_ADD(DAY, i, "DAY")) DAY
FROM
(SELECT '2015-01-01' AS DAY) a CROSS
JOIN
(SELECT i
FROM [fh-bigquery:geocode.numbers_65536]
WHERE i<=abs(DATEDIFF('2015-01-01','2015-01-15'))) b
ORDER BY DAY ASC
this outputs:
+-----+------------+---+
| Row | day | |
+-----+------------+---+
| 1 | 2015-01-01 | |
| 2 | 2015-01-02 | |
| 3 | 2015-01-03 | |
| 4 | 2015-01-04 | |
| 5 | 2015-01-05 | |
| 6 | 2015-01-06 | |
| 7 | 2015-01-07 | |
| 8 | 2015-01-08 | |
| 9 | 2015-01-09 | |
| 10 | 2015-01-10 | |
| 11 | 2015-01-11 | |
| 12 | 2015-01-12 | |
| 13 | 2015-01-13 | |
| 14 | 2015-01-14 | |
| 15 | 2015-01-15 | |
+-----+------------+---+
You can add this data to your view in the BigQuery UI by adding the project fh-bigquery
using the project menu (the drop-down next to the project name, Switch to Project ➪ Display Project). Alternately, you can navigate to the BigQuery UI link https://bigquery.cloud.google.com/project/fh-bigquery
After you add the project, the sample dataset (fh-bigquery) appears in the navigation panel.
@Pentium10 answer is the right and classic way of filling ranges. Just for fun, I wanted to also give an alternative which doesn't rely on any additional table. This solution goes like that:
Here is the whole query put together:
select date(date_add(day, i, "DAY")) day
from (select '2015-01-01' day) a
cross join
(select
position(
split(
rpad('', datediff('2015-01-15','2015-01-01')*2, 'a,'))) i
from (select NULL)) b;