Skip to content

Commit

Permalink
ENH: add back the query to dynamically get latest idc version
Browse files Browse the repository at this point in the history
  • Loading branch information
vkt1414 committed Aug 2, 2024
1 parent d063ad3 commit 20cc9d3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/sql/prior_versions_index.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ DECLARE idc_versions ARRAY<INT64>;
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]
Expand All @@ -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("""
Expand All @@ -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
Expand Down

0 comments on commit 20cc9d3

Please sign in to comment.