From 20cc9d3ddc6a58d72f58266aa34629d9ca805121 Mon Sep 17 00:00:00 2001 From: Vamsi Thiriveedhi Date: Fri, 2 Aug 2024 08:00:38 -0400 Subject: [PATCH] ENH: add back the query to dynamically get latest idc version --- scripts/sql/prior_versions_index.sql | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/sql/prior_versions_index.sql b/scripts/sql/prior_versions_index.sql index bd7261e..43ff81f 100644 --- a/scripts/sql/prior_versions_index.sql +++ b/scripts/sql/prior_versions_index.sql @@ -6,7 +6,14 @@ DECLARE idc_versions ARRAY; DECLARE latest_idc_version INT64 DEFAULT 18; DECLARE union_all_query STRING; --- Step 2: Get all idc_versions +--Step 2 +--SET latest_idc_version = ( +--SELECT max(idc_version) +--FROM +--bigquery-public-data.idc_current.version_metadata +--); + +-- Step 3: Get all idc_versions SET idc_versions = ( SELECT GENERATE_ARRAY(1, latest_idc_version) -- SELECT [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] @@ -15,7 +22,7 @@ SET idc_versions = ( --`bigquery-public-data.idc_current.version_metadata` ); --- Step 3: Generate the UNION ALL query dynamically +-- Step 4: Generate the UNION ALL query dynamically SET union_all_query = ( SELECT STRING_AGG( FORMAT(""" @@ -42,7 +49,7 @@ SET union_all_query = ( FROM UNNEST(idc_versions) AS version ); --- Step 4: Execute the complete query +-- Step 5: Execute the complete query EXECUTE IMMEDIATE FORMAT(""" WITH all_versions AS ( %s