-
-
Save cyanred9/d4db3edd0c7d2059c4b7aaeb6bfd3a95 to your computer and use it in GitHub Desktop.
[BQ Loop over days] Date loop for backfills #bigquery #sql #date #loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE i INT64 DEFAULT 0; | |
DECLARE DATES ARRAY<DATE>; | |
DECLARE event_date DATE; | |
SET DATES = GENERATE_DATE_ARRAY(DATE(2019,1,1), DATE(2019, 12, 31), INTERVAL 1 DAY); | |
LOOP | |
SET i = i + 1; | |
IF i > ARRAY_LENGTH(DATES) THEN | |
LEAVE; | |
END IF; | |
SET event_date = DATES[ORDINAL(i)]; | |
DELETE FROM `uc-puzzle-data.xxx.yyy` WHERE local_event_date = event_date; | |
INSERT INTO `uc-puzzle-data.xxx.yyy` | |
WITH | |
..... | |
; | |
END LOOP; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment