Last active
August 24, 2020 05:46
-
-
Save na0fu3y/7eaee4bcd74dac96d37735e8a5456c4b to your computer and use it in GitHub Desktop.
BigQuery で 180 日間参照されていないテーブルを出すクエリ
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
EXECUTE IMMEDIATE( | |
SELECT | |
FORMAT(""" | |
WITH | |
referenced_tables AS( | |
SELECT | |
DISTINCT referenced_table.project_id, | |
dataset_id, | |
table_id | |
FROM | |
`region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT | |
JOIN | |
UNNEST(referenced_tables)referenced_table), | |
tables AS(%s) | |
SELECT | |
table_catalog, | |
table_schema, | |
table_name | |
FROM | |
tables | |
LEFT JOIN | |
referenced_tables | |
ON | |
project_id=table_catalog | |
AND dataset_id=table_schema | |
AND table_id=table_name | |
WHERE | |
project_id IS NULL | |
""",STRING_AGG(FORMAT(""" | |
SELECT | |
table_catalog, | |
table_schema, | |
table_name | |
FROM | |
`%s`.INFORMATION_SCHEMA.TABLES""",schema_name),""" | |
UNION ALL""")) | |
FROM | |
INFORMATION_SCHEMA.SCHEMATA) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment